10

I just bought a Google Nexus One smartphone, and I want to write a small Android application for fun. Suppose I can get my current GPS coordinates, so then how can I programmatically find nearby landmarks or points-of-interest within some radius? Is there an API to get GPS geo-tagged landmarks, like in Google Earth's database?

For example, if I'm in downtown Chicago, my program would point me to all the "tourist" things to visit in that city.

Ideally, it would all run on my smartphone, but if necessary, I can have the smartphone query a webserver, which would then run more queries.

3
  • Did you look at the google maps api?
    – Jay
    Commented Apr 13, 2010 at 17:32
  • You've already been beaten to the punch; there's an app called "Places Directory" written by Google that does exactly what you describe.
    – Dan Lew
    Commented Apr 13, 2010 at 18:05
  • @Daniel Lew I don't intend to write my own application for distribution. I just want to try out different APIs. Commented Apr 13, 2010 at 18:45

5 Answers 5

5

Depends where you're getting your landmark data from. If you want to do a web query, you could run with one of the things above.

Alternatively - if you have your own data, you can stash it in the db with lat and lon values and then form bounding rectangle for a query. This Question tells you how to calculate a bounding box that covers a given radius around your current point (it will be a box, so it will be bigger than a circle....

How to calculate the bounding box for a given lat/lng location?

Using the bounding box, you can now do a query from your db where lat < maxlat and lat > minlat and lon > minlon and lon < maxlon which will give you all your points of interest within the box.

Then, using the Location class in the Android api, you can get it to calculate the bearing and distance to each of the hits and then you could for instance, sort by radius from your position.

3
  • This a great help. Suppose I want to store my own landmarks and implement my own lookup service; if I have N landmarks, I would have to do an O(N) search through all of them to find the nearest one. Is there a data structure or approach that will improve upon this search? I was thinking of implementing a two-level tree (one level of latitude, another level for longitude) or a kd-tree or a quadtree. Any ideas? Commented May 25, 2010 at 16:51
  • The idea would be that you index on lat and long, which means that finding everything within the rectangle would be fairly quick. Having done that, you then only have a limited set of things that you have to do O(n) work to. You could also start with a really small rectangle, and then query outwards (excluding your inner rectangle) to add more results as you deemed necessary.
    – Fiid
    Commented May 27, 2010 at 3:41
  • Incidently - I think real geo databases have more cleverness about this stuff. I implemented a geo search on Android using this approacdh though and it works reasonably quickly. My app finds all the airports and heliports within a 50nm radius.
    – Fiid
    Commented May 27, 2010 at 3:43
2

The quickest way to do this is:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=business+near+city");
startActivity(intent);

After geo you put your coordinates, and after q= you input your search tearms, like tourism+city. This will fire up the Google Maps app with the points of interest.

If you want to use a maps view inside your application, you would need to get the data from some service, like your own. However you could pull the data from Google's ajax search like this: http://ajax.googleapis.com/ajax/services/search/local?v=1.0&rsz=large&gl=pl&q=tourism+chicago More info here: http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_local This will give you results that have geo-coordinates and you would need to make a way of parsing the results and maybe get them into a database.

2
  • Thanks. I don't want to necessarily get the nearby points-of-interest in the form of a map. I would rather just have it returned in XML. Commented Apr 13, 2010 at 18:55
  • Well then the ajax api should work for you, but I think it only works with json.
    – Jan S.
    Commented Apr 13, 2010 at 19:49
1

Another web service you might look at is: http://developer.yahoo.com/geo/geoplanet/

1

One developer-friendly data source you can use is http://compass.webservius.com - it's a database of millions of business listings in the USA, easily searchable with a coordinate bounding box using a REST API.

1

Foursquare has a great API that gives you businesses and other places of interest given GPS coordinates. Doesn't require user sign in to access. The backing database is constantly maintained by foursquare users.

https://developer.foursquare.com/overview/venues

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.