I have some code that first of all creates some LatLng objects, as below (just one as an example):
LatLng turnOne = new LatLng(52.512657, 1.011376);
Within the onLocationChanged method I want to check the LatLng I created with the current location and if they are equal then do something (in my case trigger speech).
I have tried numerous things, such as:
Creating a LatLng from the Location object. I'm sure this might work but will the two compared LatLng objects have to be exact? If so trying to match them on the move with no threshold seems unlikely.
LatLng a = new LatLng(location.getLatitude(), location.getLongitude()); if(turnOne.equals(a)) { ttobj.speak("stuff", TextToSpeech.QUEUE_FLUSH, null); }
Creating a Location object from the LatLng. I'm not sure why this didn't work. I am comparing two Location objects and allowing for a threshold of 10 meters or less (on a road) but it didn't seem to work (I heard no speech).
Location loc1 = new Location(""); loc1.setLatitude(turnOne.latitude); loc1.setLongitude(turnOne.longitude); if(location.distanceTo(loc1) <= 10) { ttobj.speak("stuff", TextToSpeech.QUEUE_FLUSH, null); }
My question therefore is how can I either compare two LatLngs and allow for a slight threshold in tracking (5 meters say) or compare two locations.
The only thing I can find close to this question is Comparing two LatLng objects in google map v2 android but it hasn't helped me completely.