注冊百度API
http://lbsyun.baidu.com/
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=youak"></script>
wx 獲取坐標 MAP 獲得城市
wx.getLocation({
type: 'wgs84',
success: function (res) {
var latitude = res.latitude; // 緯度淆游,浮點數(shù)傍睹,范圍為90 ~ -90
var longitude = res.longitude; // 經(jīng)度,浮點數(shù)稽犁,范圍為180 ~ -180。
var point = new BMap.Point(longitude, latitude); // 創(chuàng)建坐標點
// 根據(jù)坐標得到地址描述
var myGeo = new BMap.Geocoder();
myGeo.getLocation(point, function (result) {
var city = result.addressComponents.city;
$('.city').html(city);
});
}
});