-1

Ich habe einen Zweifel in der genannten Titel. Ich kann die aktuelle Breite und Länge erhalten. Aber wenn ich reverse geoCoding verwende, um zum entsprechenden Stadtnamen oder zur Adresse zu konvertieren, zeigt nichts. Hat jemand eine Ahnung davon? Hier ist mein Codeerhalten Stadt Name, Adresse mit Breite und Länge in Appcelerator

Titanium.Geolocation.getCurrentPosition(function(e) { 

      if (!e.success || e.error) { 
       alert('Could not find the device location'); 
       return; 
      } else { 
       longitude = e.coords.longitude; 
       latitude = e.coords.latitude; 

       Titanium.Geolocation.reverseGeocoder(latitude, longitude, function(e) { 
        if (e.success) { 
         var places = e.places; 
         if (places && places.length) { 
          driverCity = places[0].city; 
          // Current city 
          driverState = places[0].address; 
          // Current State 
          annotation.title = e.places[0].displayAddress; 
          // Whole address 
          // Ti.API.info("\nReverse Geocode address == " + JSON.stringify(places)); 
         } else { 
          // address = "No address found"; 
         } 
        } 
       }); 
      } 
     }); 

Antwort

2

würde ich vorschlagen, zunächst verschiedene Variablen für die Rückgabeparameter in den Funktionen und negative Bedingungen verwenden, um Einzug zu reduzieren:

Titanium.Geolocation.getCurrentPosition(function(position) { 

    if (!position.success || position.error) { 
     alert('Could not find the device location'); 
     return; 
    } 
    longitude = position.coords.longitude; // -88.0747875 
    latitude = position.coords.latitude; // 41.801141 

    Titanium.Geolocation.reverseGeocoder(latitude, longitude, function(result) { 
     if (!result.success || !result.places || result.places.length == 0) { 
      alert('Could not find any places.'); 
      return; 
     } 
     var places = result.places; 
     Ti.API.info("\nReverse Geocode address == " + JSON.stringify(places)); 
     driverCity = places[0].city; 
     // Current city 
     driverState = places[0].address; 
     // Current State 
     annotation.title = places[0].displayAddress; 
     // Whole address 
     // Ti.API.info("\nReverse Geocode address == " + JSON.stringify(places)); 
    }); 
}); 

Dann sehen, was aus Ihren Anrufen zurückgegeben wird.

+0

Zusätzlich zu der Larrie-Antwort können Sie Drittanbieter verwenden, um die Adresse von lat-long zu erhalten. –