2016-03-16 54 views
0

我正在使用Ti.map模塊。使地址爲緯度經度ti.map

現在我想將地址改爲經緯度爲 設置註釋引腳。

,當你在谷歌地圖檢索算法箱

鍵入地址,我認爲這是很簡單的功能,雖然我不能找到Ti.map文檔中做到這一點的方式一樣?

有人能幫助我嗎?

回答

1

您可以使用谷歌API來做到這一點:

var v = encodeURIComponent("YOUR ADDRESS HERE"); 

var xhr = Titanium.Network.createHTTPClient(); 
    xhr.autoEncodeUrl = false; 

    xhr.onload = function(e){ 

     if (xhr.status == 200){ 

      if(xhr.readyState == 4){ 

       var response = JSON.parse(xhr.responseText); 

      } 

     } 

    }; 

xhr.onerror = function(e){}; 

var url = 'https://maps.googleapis.com/maps/api/geocode/json?address='+v+'&sensor=false'; 
xhr.open('GET', url, true); 
xhr.send(); 

如果你想從你的緯度/經度的地址,你可以使用Ti.Geolocation.reverseGeocoder()方法:http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-method-reverseGeocoder

+0

它將您的緯度/經度改變爲地址。我想要做的是將地址更改爲緯度/經度。但是我很驚訝Ti.geolocation有這個功能。不知何故Ti.Geolocation可以訪問地址數據庫。 – whitebear

+0

謝謝@Thomas,它就像一個魅力。而這個簡單的谷歌API不需要驗證。這很好。 – whitebear