John van de Waeter 7 Posted January 24, 2021 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? tia! John Share this post Link to post
Pat Foley 51 Posted January 24, 2021 On webbrowser side try a reload. Or the equivalence of the F5 key in a webbrowser. Share this post Link to post
John van de Waeter 7 Posted January 24, 2021 Pat, It's not from a webbrowser, it's from a Delphi-FMX app. Share this post Link to post
Pat Foley 51 Posted January 24, 2021 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); var URLString: String; begin // code for previous step goes here // Show Map using Google Maps URLString := Format Quote Share this post Link to post
John van de Waeter 7 Posted January 24, 2021 Pat, 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
Pat Foley 51 Posted January 24, 2021 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
John van de Waeter 7 Posted January 24, 2021 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
Pat Foley 51 Posted January 24, 2021 procedure TForm1.LocationSensor1LocationChanged( ... // Translate location to address if Assigned(FGeocoder) and not FGeocoder.Geocoding then FGeocoder.GeocodeReverse(NewLocation); //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
Pat Foley 51 Posted January 24, 2021 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
Rollo62 536 Posted January 25, 2021 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 ). I usually do like this: procedure TForm1.LocationSensor1LocationChanged(Sender: TObject; const AOldLocation, ANewLocation: TLocationCoord2D); var LDecSeparator: String; LNewLocation : TLocationCoord2D; begin LNewLocation := ANewLocation; TThread.ForceQueue( //<== Ensure that the UI is touched only from UI thread nil, procedure begin 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 ); end; Share this post Link to post
John van de Waeter 7 Posted January 25, 2021 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
John van de Waeter 7 Posted January 26, 2021 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: else begin Addr := FGeoRevAddress; Addr.adminarea:=''; // <--- added addr.postalcode:=''; // <--- added addr.locality:=''; // <--- added Share this post Link to post