Jump to content
John van de Waeter

GeocodeReverse on Android

Recommended Posts

Hi All,


In my app I tried this sample to test Geocode Reverse, to find a location's postal code.


Works great on iOS, but works only once on Android. (tested on Android 6 and 9).


First time lookup Geocode reverse works, but subsequent lookups give the same result as the first one.

Have to kill the app and restart to have a new lookup.


I tried to dispose the TGeoCoder, so it would be recreated at every lookup, but it didn't have any effect.


Any ideas?






Share this post

Link to post

On webbrowser side try a reload.  Or the equivalence of the F5 key in a webbrowser.   

Share this post

Link to post

Ok  from your sample is your likewise event happening and is then using cached data or simply not  getting new data since in background. 

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const OldLocation, NewLocation: TLocationCoord2D);
  URLString: String;
  // code for previous step goes here

  // Show Map using Google Maps
  URLString := Format



Share this post

Link to post


Still, no, no LocationSensor involved. I already have coordinates.

I just want to lookup (georeverse) the postalcode from a set of lat/long.


Meta code:

1: Input lat, long;

Find postalcode using georeverse

Works on both iOS and Android

2: Input another different set of lat/long;

Find postalcode;

Works on iOS, but gives result of first lookup (1) in Android.



Share this post

Link to post

I just tried the FMX.locationdemo on my android and the current address is working on that demo. So maybe try the location demo and try edit boxes on it to 

see what that demo does.        

Share this post

Link to post

Well, actually because I always doubt myself, I tried this demo on Android.


Start it, enable LocationSensor. Works, adress info is correct.


Leave the demo app running, start walking a couple of hundred meters.


The location coordinates and map synchronizes with the position, the current address does not.


Stop LocationSensor, start LocationSensor: still old address.


Stop app, restart app, address info ok.



Share this post

Link to post
procedure TForm1.LocationSensor1LocationChanged( 
// Translate location to address
    if Assigned(FGeocoder) and not FGeocoder.Geocoding then

//As described earlier, after Reverse Geocoding is completed, an OnGeocodeReverseEvent is fired.


From sample.   I will bring out the win 7 machine with the FMX stuff on it but probably two days out.  I want to make two FMX programs this year Phone app that caches local data or least miles from North pole and miles West of home when cell towers down or out of range. A program to read topo map from Garmin 600t would nice too.      

Share this post

Link to post

Hey,  It must be same issue as before you need to force repaint.  The FMX.locationdemo updated location data when I changed from map view back to show location data. 

Share this post

Link to post

I would put one step of decoupling between the event and the processing,

since the data maybe fired from external system, and I never trust that the thread or timing is correctly decoupled under all circumstances (maybe you call that paranoic :classic_smile:).

I usually do like this:

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const AOldLocation, ANewLocation: TLocationCoord2D);
  LDecSeparator: String;
  LNewLocation : TLocationCoord2D;
    LNewLocation := ANewLocation;
    TThread.ForceQueue(  //<== Ensure that the UI is touched only from UI thread
            LDecSeparator := FormatSettings.DecimalSeparator;
            FormatSettings.DecimalSeparator := '.';
            // Show current location
            ListBoxItemLatitude.ItemData.Detail  := Format('%2.6f', [ LNewLocation.Latitude  ]);
            ListBoxItemLongitude.ItemData.Detail := Format('%2.6f', [ LNewLocation.Longitude ]);
        end );


Share this post

Link to post

Hi Rollo62,

It's not a matter of UI-refresh.

I added a counter to the callback of the reverse geo lookup. It counts and it displays the counter.

Like City=Amsterdam 1

       City = Amsterdam 2


The lookup is executed, just returning the same result every next time (on Android).



Share this post

Link to post

Found it, I guess...


In System.Android.Sensors,  class procedure TAndroidGeocoder.GeocodeReverseRequest


The FGeoRevAddress was filled with data from the previous request.

The code only fills the fields that are empty. So after one request, the fields where not empty and new data never got into the fGeoRevAddress.


I applied just a quick fix for what I needed (city, postalcode, adminarea)

of course this needs a more proper solution... 🙂


 My quick fix:

    Addr := FGeoRevAddress;

    Addr.adminarea:='';    // <--- added
    addr.postalcode:='';   // <--- added
    addr.locality:='';     // <--- added




Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now