openstreetmap - closest way-object to user location - openstreetmap

I am playing around a bit with openstreetmap data.
What I want to get is the closest "road" (i.e. way with tag 'highway' set to certain values) to the users position.
At the moment I use the API to query all Objects in a square around the user and then parse all the way elements, check their tags, check their distance to the user and so on
But that doesn't sound to elegant to me.
Is there a better solution ? maybe through the API or by installing the openstreetmap data in a local DB somehow to be able to query that directly ?
would be great if someone could point me to the right direction.
Thanks in advance.

please use "Read-Only Data APIs" for getting Data.
You must not use the "editing API" for read-only purposes or projects.
(see Terms of use)
For your purposes I would use OSM Server Side Script

Related

How to use overpass api?

I am a total newbie so this may be a silly question, but I can't find any tutorials on how to query overpass api to display things on own website. Do I install it on my server or is there a code to query it in the script?
What I want to achieve is to have a searchbar on one page to search for tags, and that would display one random point with that tag on the other page with a leaflet map.
But I am struggling to even display any points on it. Would it be actually better to have a local geojson file with set list of points in one town if I want to limit them to just this town anyway?
I will be grateful for any help, it's a first time I am doing something like this and it horribly stresses me out
You can visually run and try overpass queries using http://overpass-turbo.eu/.
In order to unload the overpass server, it would be a good idea to fetch the data once (and update regularly) and host them on your own server (also pay attention to the terms of use of the specific APIs, they might limit the number of requests per hour or prohibit using the for autocomplete).
To query the server from an application, GET from https://overpass-api.de/api/interpreter?data=, followed by your request (the same you would type into overpass turbo, just without line breaks).
It is also possible to host an overpass instance on your own.
If you need to learn the Overpass Query Syntax first, you can read the docs.

Options to create a reverse geocode system using OpenStreetMap

I need to create a local reverse geocode service for my specific country using open source maps.
My first option is OpenStreetMap so I downloaded my country PBF file.
Can anyone give any idea on how to start using this data? or other options?
There are already various search engines for OSM available. The most popular one currently is Nominatim. It supports both geocoding and reverse geocoding.
Well, you could start of by reading the wiki, I guess it would be interesting to find out which node / way / relation tags you would use as an input. Apart from that you should have an understanding of the best data structures for the task, I guess you want to perform nearest neighbor queries, so you might need to implement / use an R-Tree for that...

How to get list of search results of location like in google maps

I am developing an application in which when the I enters an address ,I fetch latitude and longitude of that address and drop the pin.
But what I want is like I enter any business or address then a list of that search comes in google maps and multiple pins are dropped for that address.
I also want this feature to get include in my app but when I pass my address only one location comes not a list like it comes in google maps.
Please help me if anybody knows how google maps searches a couple of locations for that address
ex:- caribou coffee, chapel hil
Any suggestion will be highly appreciated
Thanks in advance!
This functionnality is provided by Google Places API.
If you are looking for an algorithm it's using the harvesine forumula or a quadtree data structure. A quadtree or a r-tree in maps applications most likely it uses a space-filling-curve to sort the quadtree. If you look for sfc I recommend a hilbert curve because it has better space fill quality but normally they uses a z-curve.

Google Maps API: Requesting any place labels given longitude and latitude?

I am working on an iPhone map application and wanted to know whether it was possible to request any labels visible on Google Maps given a longitude/latitude and radius?
For example if I gave the following location to this Google Maps API, I would get back McCullough Hall, Moore Hall, etc. The list would be any place labels visible on the map (doesn't have to be just restaurants, businesses).
If this is possible can you direct me to where I can learn more about this. If this isn't possible, can you direct me towards another API where it is possible?
Look into Googles reverse geocoding, I think that's what you're looking for.
The short answer, you cannot!.
The only way is to search for places by name and get a reference key to query the place details including lat/lng. Not the other way around.
IMHO, this is mainly a policy of Google instead of being technical limitation.

Get zip code from latitude, longitude?

I want to get zip code from users current location(Latitude, Longitude), I had used MKReverse Geocoder delegate methods, but sometimes I am not able to get zip code information based on latitude & longitude (valid values). Are there any other alternatives for MKReverseGeocoder ? ZipCode database are specific to countries, that's why I don't want to use them. Any other idea or clue?
Thanks
Consider the GeoNames web service. It's a complete geocoding/reverse geocoding suite under a Creative Commons attribution license. You can either download their data, or hit their web service. The best thing is, they don't require any API keys or licensing silliness--you just hit their web app and bang you got data.
Here's an example: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=36&lng=-79.08 That'll return you a JSON object for the zip codes around the Chapel Hill, NC area.
It's also international. Here's Seaford, England, and the only difference is the lat/lng pair I'm sending: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=50.5&lng=0.08
Then you need to learn to make web requests and parse JSON (if you don't already have a grip on those things), and you're all set.
This is actually a tricky question. Using a geocoding solution like GeoNames is likely to lead to major errors for a lot of queries. The reason for this is that GeoNames by looking up the record in their database that is closest to your query point and then returning the ZIP code they have on record for that point. This works great when your query point is right on top of a record in their database, but can lead to errors otherwise. For example, if their nearest record is a few blocks away in a different ZIP code, you'll get the wrong answer.
The US Census Bureau has created maps of the ZIP codes:
https://www.census.gov/geo/reference/zctas.html
Please see their notes on that page.
I have also worked on a project that uses the Census maps to provide an API that gives back the ZIP code for a given latitude and longitude. It is at:
http://askgeo.com
We offer both a web API and a Java Library that you can run on your own server. The library has excellent performance. Since our site offers additional information than just the ZIP code, you can read about our ZIP code service here:
http://askgeo.com/database/UsZcta2010
And you read about the documentation for the Web API here:
http://askgeo.com/#web-api
The GeoNames methodology is fundamentally flawed for this type of query. If you are looking for the polygon that contains a given query point, you need a map with the polygons, and you need a spatial index to provide fast look-ups. GeoNames has neither. AskGeo has both.
If you have a free db (available from that site? Just search for zip code database and you'll see it)
then you can run an internal SQL query testing for nearby lat/longs. That way you won't need to worry about licensing a web service.
You have three options then. SQL BETWEEN statement, the hypotenuse equation, or Haversine. Haversine being the best, luckily it's tutorial'd elsewhere
EDIT:
Couple of other options I've seen recently:
http://developer.yahoo.com/geo/placefinder/guide/index.html
http://jamiethompson.co.uk/projects/2010/04/30/an-open-free-uk-postcode-geocoding-web-service/
http://www.postcodeanywhere.co.uk/geocoding-service/api.aspx
--
Take a look at the Google Maps API - Reverse Geocoding (only useful if embedding results in a Google Maps interface).
Sample code here:
Get Zipcode from results[1].formatted_address
https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse