JS免费天气API接口示例
//API天气接口(https://www.tianqiapi.com/)
$.ajax({
type: 'GET',
url: 'https://www.tianqiapi.com/api/',
data: 'version=v1&city='+city,
dataType: 'JSON',
error: function () {
alert('网络错误');
},
success: function (res) {
//alert(res.data[0].hours[0].tem+" "+res.data[0].hours[0].wea);
$("#weather").html(res.data[0].hours[0].wea+" "+res.data[0].hours[0].tem+" "+res.data[0].hours[0].win+" "+res.data[0].hours[0].win_speed);
// 遍历数组
// for (var i = 0; i < res.data[0].hours.length; i++) {
// $('#hours').append('<li>' + (i + 1) + ': 时间: ' + res.data[0].hours[i].day + ' 气温: ' + res.data[0].hours[i].tem + ' </li >');
// }
}
});
H5+百度地图实现精确定位
$(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
})
function showPosition(position) {
var x = position.coords.longitude;
var y = position.coords.latitude;
var ggPoint = new BMap.Point(x, y);
console.log(ggPoint);
var geoc = new BMap.Geocoder();
var pt = ggPoint;
geoc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
$("#map").html("当前位置:"+addComp.province + ", " + addComp.city);
});
}