1

Ti.GeoLocation.forwardGeocoder()没有将非美国地址转换为 lat 和 long 值。

下面的示例代码。

Ti.GeoLocation.forwardGeocoder('Hyderabad, India', function(e){
var lat = e.latitude;
var long = e.longitude;
});

使用这段代码,我们得到 lat 和 long 值是未定义的。

4

3 回答 3

1

获取美国地址以及世界其他任何地方(谷歌可以找到)并在钛地图上显示经度/纬度的正确方法。

下面的代码使用字符串变量:myAddress

var myAddress = address + ','+ city + ',' + postal + ',' + country //'Vieux Port, Montreal, Quebec, H2X3R4, Canada'
var xhrGeocode = Ti.Network.createHTTPClient();
xhrGeocode.setTimeout(120000);
xhrGeocode.onerror = function (e) {
    alert('Google couldn\'t find the address... check your address');
};
xhrGeocode.onload = function (e) {
    var response = JSON.parse(this.responseText);
    if (response.status == 'OK' && response.results != undefined && response.results.length > 0) {
        longitude = response.results[0].geometry.location.lng;
        latitude = response.results[0].geometry.location.lat;
    }
};
var urlMapRequest = "http://maps.google.com/maps/api/geocode/json?address=" + myAddress.replace(/ /g, '+');
urlMapRequest += "&sensor=" + (Ti.Geolocation.locationServicesEnabled == true);
xhrGeocode.open("GET", urlMapRequest);
xhrGeocode.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhrGeocode.send();
于 2013-02-13T01:06:22.440 回答
0
            var addrReq = Titanium.Network.createHTTPClient();
            var addrUrl = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address="+ query;
            addrReq.open("GET",addrUrl);
            addrReq.send(null);


            addrReq.onload = function()
            {
                 var response = JSON.parse(this.responseText);

                  if(response.status == "OK"){



                    LT.Customlat=response.results[0].geometry.location.lat; 
                    LT.Customlon=response.results[0].geometry.location.lng; 

}

于 2013-10-18T19:21:32.860 回答
-1

您需要使用 google REST API 推出自己的解决方案,底层 Titanium API 不支持非美国地址

于 2013-02-05T15:10:46.057 回答