逆地理編碼,經緯度=》地址信息 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.regeocode.addressComponent.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); //將即將緯度存到本地 } }); });