Issue
I'm working in a App to populate a MapView with a list of favorite sites. Now, I have all the markers in the MapView, but I would like to do a event on this markers that when I press one of them, launch another activity.
I try to do a onTouch event that get the X and Y coordinates and after this, check in the Database if this GeoPoint is, but It's imposible to check 'cos the geopoint are so accurated with a lot of decimals and It's so difficult to get the same as I have in the Database.
The question is: Are there some way to do a event in this marker???
Solution
For a "list of favorite sites", assuming a modest number of sites, ItemizedOverlay is the typical overlay to use. If you are using that, simply override the onTap() that supplies the index of the particular marker that the user tapped upon.
If you are using Overlay instead of ItemizedOverlay, you can find the item in your database that is closest to the user's tapped coordinates, using something like this:
SELECT MIN(ABS(Latitude - ?) + ABS(Longitude - ?)), _ID FROM Sites GROUP BY _ID LIMIT 1;
where you supply your latitude and longitude as a two-element String[] to rawQuery() and adjust the column names as appropriate. Note that I have not tried this query personally, so there may be issues with my conversion to SQLite.
(derived from T-SQL: Finding the closest location of an object on a map grid)
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.