Titanium Ti.GeoLocation.forwardGeocoder()未将非美国地址转换为纬度和长值

时间:2013-02-05 09:57:29

标签: titanium titanium-mobile

Ti.GeoLocation.forwardGeocoder()未将非美国地址转换为纬度和长值。

以下示例代码。

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

使用此代码我们得到lat而长值未定义。

3 个答案:

答案 0 :(得分:1)

获取美国地址以及世界上其他任何地方(Google可以找到)的正确方法,并在钛地图上显示长/拉。

以下代码使用字符串变量: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();

答案 1 :(得分: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; 

}

答案 2 :(得分:-1)

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