hansemannn / titanium-googlemaps

🗺 Use the Google Maps SDK in Titanium
Other
87 stars 26 forks source link

Support the Reverse Geocoder API #73

Closed hansemannn closed 7 years ago

hansemannn commented 7 years ago

@yozef for your review! 😊

mention-bot commented 7 years ago

@hansemannn, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yozef and @bitfabrikken to be potential reviewers.

yozef commented 7 years ago

Absolutely :)

Currently using Ti's Ti.Geolocation.reverseGeocoder now :)

Will update here..

hansemannn commented 7 years ago

I guess Google's API is restricted by the API key you use. But the results are pretty advanced, so people might prefer it.

yozef commented 7 years ago

I'm using this code:

var Map = require('ti.googlemaps'); // iOS Google Maps
Map.setAPIKey("AIzzzzzxxxxxxxxx");
// on map panning,  I get _longitude, _latitude
Map.reverseGeocoder({
    latitude: _latitude,
    longitude: _longitude
    }, function(e) {
        alert('Address found!');
        $.addressTF.value = e.firstResult;
        Ti.API.info(e.firstResult);
        Ti.API.info(e.results);
});
 Script Error {
[ERROR] :      column = 39;
[ERROR] :      line = 1149;
[ERROR] :      message = "undefined is not a function (evaluating 'Map.reverseGeocoder')";

I wonder if this is on my end... still debugging...

yozef commented 7 years ago

I see reverseGeocodeCoordinate in the code :p

yozef commented 7 years ago

Works!

Though README should state:

maps.reverseGeocodeCoordinate({ // not reverseGeocoder
    latitude: 36.368122,
    longitude: -120.913653
}, function(e) {
    alert('Address found!');

    Ti.API.info(e.firstResult);
    Ti.API.info(e.results);
});

Also the Object returned is very different than ti.map (for Android) nort sure if we should return the same object structure?

I can do that if you think it's better to have the same structure between ti.googlemaps (iOS) and ti.map (Android)

hansemannn commented 7 years ago

Good point! I updated the api to reverseGeocoder with 3 params (lat, lon, callback), renamed the callback properties to places and firstPlace (specific for this module, makes it easier to access the best match. I also moved the lat and lon from the coordinate dict directly to the root of the result dict. Oh, and I added the code and success keys for consistency. Check it out!

yozef commented 7 years ago

Looks good!