Thursday, 15 July 2010

android - Comparing LatLng and/or Location Objects -



android - Comparing LatLng and/or Location Objects -

i have code first of creates latlng objects, below (just 1 example):

latlng turnone = new latlng(52.512657, 1.011376);

within onlocationchanged method want check latlng created current location , if equal (in case trigger speech).

i have tried numerous things, such as:

creating latlng location object. i'm sure might work 2 compared latlng objects have exact? if trying match them on move no threshold seems unlikely.

latlng = new latlng(location.getlatitude(), location.getlongitude()); if(turnone.equals(a)) { ttobj.speak("stuff", texttospeech.queue_flush, null); }

creating location object latlng. i'm not sure why didn't work. comparing 2 location objects , allowing threshold of 10 meters or less (on road) didn't seem 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 hence how can either compare 2 latlngs , allow slight threshold in tracking (5 meters say) or compare 2 locations.

the thing can find close question comparing 2 latlng objects in google map v2 android hasn't helped me completely.

just provide reply this.

to compare global latlng object such as:

latlng alatlng = new latlng(51.116492, -0.541767);

to location argument provided in:

public void onlocationchanged(location location)

works fine using:

location locationone = new location(""); locationone.setlatitude(alatlng.latitude); locationone.setlongitudealatlng.longitude); float distanceinmetersone = locationone.distanceto(location);

android

No comments:

Post a Comment