0

I am trying to build a an android application that can determine the type of highway the user is on by latitude and longitude coordinates. Is there a way to query overpass turbo to retrieve the type or classification of highway ?(whether it is motorway, trunk, primary, secondary, tertiary or residential) I was not able to find any relevant tutorials or documentation to do so. Can I implement a query in a Java class method as described below:

LocationManager lm(LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
@Override public void onLocationChanged(Location location)
{ 
double longitude = location.getLongitude();
double latitude = location.getLatitude(); 

/*query overpass turbo to classify highway*/
/*store retrieved classification type as a string*/

}

And instead of fetching all ways tagged as highways around the given coordinate, can the current position be identified as to whether the way is which type of highway?

  • You need a simple HTTP query. Where exactly are you stuck? What have you already tried? – scai Sep 20 '19 at 07:02
  • @scai thank you so much for the reply, could you help me with few lines of code as to write an overpass HTTP query and store the result/highway classification type in a string ? considering I already have method defined to get location coordinates that is two variables currentLat and currentLong to store the current latitude and current longitude. I would be really grateful if you can help me with it! – devthepenguin Sep 20 '19 at 08:02
  • https://stackoverflow.com/questions/28950359/retrieving-xml-attributes-from-osm-xml-file-android What changes can I make to this similar code to retrieve highway type instead of maxspeed? – devthepenguin Sep 20 '19 at 08:51
  • See my answer, I modified this query to return highways. – scai Sep 20 '19 at 09:08
  • Please take particular note of the **Usage Policy for the public Overpass API instances**. Also, you need to supply a proper HTTP User-Agent header to identify your app. The use case you describe is generally discouraged for the public instances, as it creates too much load. But you're free to set up your own Overpass API instance. – mmd Sep 22 '19 at 11:06
  • @mmd Thankyou for the information! Can you provide link to documentation or an example that helps setting up an Overpass API of our own? – devthepenguin Sep 24 '19 at 16:02
  • https://overpass-api.de/ has all the details you need. – mmd Sep 24 '19 at 16:19

1 Answers1

0

You need to look for ways with a highway tag. You can use the following Overpass API query to locate all ways tagged as highway within 100 meters of 51.033,13.749 (lat, lon):

[out:xml][timeout:25];
way(around:100,51.033,13.749)[highway];
out body;
>;
out skel qt;

You can see the result on overpass turbo or download the results directly via Overpass API.

You can use the last link for building a simple HTTP request from within your application. Note that Overpass API supports different output formats such as XML and JSON, depending on your query.

scai
  • 20,297
  • 4
  • 56
  • 72
  • Is it possible to implement this query in the method described in the question which I have just edited , if yes how can it be done? – devthepenguin Sep 20 '19 at 10:06
  • Yes, it is. Just add a HTTP call and parse the XML or JSON response. Where exactly are you stuck? What have you already tried? – scai Sep 20 '19 at 11:13
  • I have defined getter methods to get the latitude and longitude. Is the XML downloaded when this query is made or is the query directly parsed as XML I mean where is the location or filepath in my project where its stored? Could you please help me? – devthepenguin Sep 24 '19 at 16:00
  • I followed this example wiki.openstreetmap.org/wiki/Java_Access_Example but when I pass my query string as "http://overpass-api.de/api/interpreter?data=way [\"highway\"~\".\"] (around:5,lat,lon); ( ._; >; ); out;"; file not found exception is thrown – devthepenguin Sep 25 '19 at 05:26