使用定位,逆地理编码,经纬度《=转=》地址信息、逆地理编码,地址《=转=》经纬度,贼方便!!!!
经纬度转地址信息
// 逆地理编码,经纬度=》地址信息
var lnglat = [lng, lat] AMap.plugin('AMap.Geocoder', function () {
var geocoder = new AMap.Geocoder({
city: '010',
//城市设为北京,默认:“全国”
radius: 1000,
//范围,默认:500
extensions: 'all',
});
geocoder.getAddress(lnglat, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
// geocoder_CallBack(result);
// console.log(result, "result");
self.city = result.regeocode.addressComponent.city;
self.resultData = result.regeocodeaddressComponent.city;
localStorage.localCity = result.regeocode.addressComponent.city;
localStorage.timestamp = new Date().getTime();
localStorage.position = JSON.stringify(position);
//将即将纬度存到本地
}
});
});
地址信息转经纬度
// 逆地理编码,地址-》经纬度
var address = '山东省苍山县';
//详细地址
AMap.plugin('AMap.Geocoder', function () {
var geocoder = new AMap.Geocoder({
city: '010',
//城市设为北京,默认:“全国”
radius: 1000,
//范围,默认:500
extensions: 'all'
});
geocoder.getAddress(address, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
// geocoder_CallBack(result);
// console.log(result, "result");
self.city = result.regeocode.addressComponent.city;
self.resultData = result.regeocode.addressComponent.city;
localStorage.localCity = result.regeocode.addressComponent.city;
localStorage.timestamp = new Date().getTime();
localStorage.position = JSON.stringify(position);
//将即将纬度存到本地
}
})
});
爱好写博客,看博客,论博客,知而不言,享而不傲,吾独爱之。