I want to get the coordinates of a building with geocoding. At the moment I use the GeoCoder class for android to get from the selected address the coordinates, but these are not corresponding to the edge of the building. OSM is containing these information for each building, but I do not know how to get these information with the GeoCoder class. Is there a possibility to use OSM with the geocoder class for android to get this information?
This is probably a little bit more complicated. First, OSM doesn't have for every address a building. And sometimes a building contains several addresses, or an address can belong to several buildings.
But as a first step you can use Nominatim for geocoding to obtain the coordinates for a specific address. And afterwards pass these coordinates to the Overpass API and search for nearby buildings.
Example:
We are searching for the building for the address Franzweg 4, Dresden. The Nominatim query could look like this (assuming we want JSON output):
http://nominatim.openstreetmap.org/search.php?q=Franzweg+4%2C+Dresden&addressdetails=1&format=json
It returns an exact match because the address exists in OSM's database. You can see that by looking at the address details, both *house_number* and road match. We even get a corresponding way with ID 94892819 which has the building tag and contains the coordinates of the building outline when querying the API for the way ID (see the API documentation).
But as already stated not every address belongs to a building. For example when searching for Huttenstraße 14, Dresden we also get an exact result but the returned way with ID 240398228 belongs to an area. This area contains a building which consequently belongs to this address. Nominatim also returns a bounding box, in this case 51.0508041381836,51.0514030456543,13.7778491973877,13.7796478271484. We can use it for retrieving objects inside that area. If you don't have a local copy of OSM's database you can use the Overpass API with the following query:
<osm-script output="json">
<query type="way">
<has-kv k="building"/>
<bbox-query e="13.7796478271484" n="51.0514030456543" s="51.0508041381836" w="13.7778491973877"/>
</query>
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton"/>
</osm-script>
This query returns all ways with the buildings tag in the given bounding box. You can use overpass turbo to visualize the result. As you can see, the bounding box contains more than one building but only one of them is inside the area. So you have to go through the coordinates of each of the building to see which one fits. Remember, one address could belong to multiple buildings, so there can be more than one single match.
Then there is also a third case where the address is a single node. For example the result for Striesener Straße 38b returns the node with ID 1615986605. Here the node is actually a member of the building way so it is easy to determine the corresponding building. But this is not always the case, you might need to run another Overpass API query to determine nearby buildings and, again, see which one fits best.
Related
I have a gps coordinate, I wish to get a list of adresses inside it's certain radius. From these adresses I wish to select the ones that are companies and contain specific sector name. (clothing, finance, metallurgy, etc..), I thought the returned api object may contain the necessary information to make the distinction. Is there a free api that has the necessary functions to bring me closer to my goal ? (like google maps, google places, yahoo placefinder, and similar applications.)
Note: I use the MVEL language, I guess it has access to some Java functions so you can consider me writing Java, but any information considering the MVEL language is also appreciated.
Note2: Radius is not an essential requisite, it would be enough if I found the adresses in a certain district. The classification however, is necessary.
I think you can take a look into :
GoogleMapServicesJava
Particulary into the Places API service :
Places API
Where you can query a search sort by radius, place type, etc...
Hope that will help !
With Google Places API, I'm able to select a location and get several properties including its name, website, ph number etc.
However, i need to get the place category (food, gas station etc) but the method getPlaceTypes() gives me a List with integers, not a string/sequence of chars.
Also, how can I get paragraphs of info of that specific place? Is that possible? Or do I have to scrape from websites myself?
Thanks.
Here you can find the Place Types supported by Google Places API. The list of integers that you are receiving is of the well known types that you can find here. So you will need to transform the integers into your own text.
With Google Places is not currently possible to get detailed info of a place, not even using the more detailed place details that you receive when you query the Places API Web Service.
no api gives you the categories instead you have to explicitly provide category name in parameter for example for getting near by places.You can find categories list here https://developers.google.com/places/supported_types
i want to build a weather app and i have some problems.
my big problems is places names! you know, i want that user find his location with two ways. with GPS and by searching. but my problem is that place names. how can find a database from whole places in the world?!
is it good idea that i store them in a database in my server? or there is some services that provide this functionality? if i have to create my own database how i can create a database like that. is there a database with city names and latitude/ longitude and other information? if a new location created how i can add it to the system? by hand?
the second problem is that after catching the city name how i can find that locations latitude/ longitude? it seems google has a Geocoder service but i don't know how it works. please help me. i just want to select a city name and find related coordinates...
The Google Maps API provides you with Geocoding, which allows you to turn strings like 'Santiago, Chile' or 'New York', into proper latitude/longitude coordinates. So in your code, you should perform an HTTP GET request to a URL like this one:
http://maps.googleapis.com/maps/api/geocode/json?address=Santiago,+Chile&sensor=true
And it returns a JSON object with a properly formatted address along with latitude and longitude information of the place you were looking up.
It's explained very thoroughly in the Google Maps API Geocoder documentation, so you should probably take a look at that. I'm no expert in Android development, but there should be some library that allows you to easily access what the Maps API has to offer in a clean way.
Maps API also provides you with a solution for Place Searching, and even input autocompletion, but all the examples I see are on JavaScript/HTML, so I'm not completely sure if there's an alternative in plain Java/Android to what you're trying to do. Nevertheless, you should take a look at basic place searching and place search autocompletion so you get a general sense of how it works.
There's an entire section in the Google Developers website dedicated to the Maps API on Android, so make sure to take a look at that aswell and you might find more useful information - sadly I have no experience with Android whatsoever so I can't really point you in any direction.
Good luck!
You could use the Google Maps Geocoding API. Querying coordinates returns a JSON response containing the current location in multiple levels of detail that you could parse.
E.g. for the position lat:40.714224 long: -73.961452, the query URL would look like the following:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
The result now contains the city and country, beside much more.
You can find more information on the API here: https://developers.google.com/maps/documentation/geocoding/
You could also try http://openweathermap.org/
I haven't used this extensively but I tried it enough that I know it works. It lets you query by location name or geographic coordinates, and the city name is included in the responses along with plenty of other data.
http://api.openweathermap.org/data/2.5/weather?lat=xx&lon=xx returns a weather object with city name & related data. API key is even optional so you can try it out very quickly.
How do mobile apps like yelp and gasbuddy find a list of nearby restaurants/gas stations? I am creating an Android app and have a list of locations in my database. I want to give the user all the nearby locations from my database based on the user's current location. What is the best way to go about it? I am using Java.
Some databases actually have this built in; for example here's a StackOverflow question about spatial queries in Postgres, which should set you on the right path. Your app would send coordinates to a server, which would use those coordinates to query a postgres database directly.
This link may be helpful http://www.dreamincode.net/forums/topic/92885-distance-between-2-points/
when you get the distance just compre it with if or whatever you want and then show it or save.
I'm working on my first android application that uses the Google Places API. The issue I'm running into is that I don't know how to filter out the search results to only show the particular places I want and not everything within that type. For example, say I had a list of specific type of restaurant across the country and I wanted to only show those particular places how would I filter out those results for just the ones I wanted to show in my application. So say I wanted Italian restaurants but not just any random one, I want to display the ones that were part of a particular restaurant group or by a specific chef. Is there a way I can filter out just those if I have a list of their locations already? Thanks!
There is no exact way to do this with the Places API. You could possibly pass the restaurant group or chef name as a keyword parameter in your request. As the documentation states, the keyword parameter is:
A term to be matched against all content that Google has indexed for
this Place, including but not limited to name, type, and address, as
well as customer reviews and other third-party content.
If you also have the places you could try match the locations with the ones returned from your search, but this may not be reliable as the exact location Google has for the place may differ from the location you have for the place.