js高德地圖api根據地址獲取地址經緯度

var location = [];
function getAddrGeo(addr) {
  //獲取某地址的經緯度可用於移動端跳轉app導航
  $.ajax({
    type: "GET",
    url:
      "http://restapi.amap.com/v3/geocode/geo?key=你的高德key&s=rsv3&address=" +
      addr.trim(),
    success: function (response) {
      location =
        response.geocodes[0] && response.geocodes[0].location.split(",");
    },
    error: function (e) {
      console.log("地址座標獲取失敗", e);
    },
  });
}

當在開發移動端想要獲取當前位置經緯度信息高德有個接口,可是要注意是高德的座標系,其餘地圖要使用的話可能要轉換下,並且貌似是ip定位,可能會有些小誤差ajax

相關文章
相關標籤/搜索