After searching around it appears that many people already have the lat/long data of the geographic points of interest they are interested in reverse-geocoding.
In my scenario I know a starting location and would like to find all points of interest (mainly residences within a neighborhood) that lie within a specific radius (say, 1 mile).
The first step is simply specifying a starting point and a radius to search within but I can't seem to figure out how to do this using the the Google Geocoding API (I'm not tied to Google... just figured I'd start there).
I am currently working in python (geopy and pygeocoder) but will eventually port it to iOS.
Any pointers would be much appreciated.
I think you may be going down the wrong path with the Google Geocoding API. What you probably want to use is Google Places API.
One (simplified) way to think about is geocoding takes in a point and returns a point. What it sounds like you want to do is pass in an area, defined by a central point and a radius, and receive a collection of points contained within that area. It looks like the Google Places API can help you with that.
Have you considered using OpenStreetMap for your task? With the help of the Overpass API you can query for all data within a given bounding box. For example this query returns all data within the current view. It uses the overpass turbo for visualization and the Overpass API only in the background but of course you can also use the Overpass API directly for returning raw data as XML or JSON.
You can even specify which exact data categories to return, for example all shops selling clothes. Take a look at commonly used tags and the Overpass API language guide for more information.
In case you haven't already, check out Radar Search & Nearby Search
https://developers.google.com/places/documentation/search#RadarSearchRequests
Related
I've got this thing to do, when we give coordinates (the latitude and longitude) as an input then the required map should be shown in the output with the help of PySimpleGUI, in Python language, of course.
So, any ideas on how to start this thing?
If you just want to show a map with a satellite image for a given lat/lon coordinate, take a look at Google's "Maps Static API". All you have to do is generate a URL with the appropriate parameters, and this API will return an image of your place and zoom level (and other parameters). As the name implies, it generates a static map image, instead of the interactive maps generated through the normal Maps APIs.
More info in the documentation:
https://developers.google.com/maps/documentation/maps-static/overview
Not that if you are thinking about "extracting" images from these maps, make sure to review the terms of service, which generally prohibit bulk extraction of data. https://www.google.com/help/terms_maps/
I am using Google MAPS API in python:
https://github.com/googlemaps/google-maps-services-python
To get the information about a place I am using
result = gmaps.places("restaurant",location=(lat,lng),radius = r)
Now on changing the radius r to different values( I have tried for as low as 1) I always get 20 results. This is not possible, because you cannot have 20 restaurants in 1 m. Any fix for this?
Thanks for help!
I am afraid that it is posible cause the API is intended to work like that, as stated in the documentation:
"a location and a radius — You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Places service to prefer showing results within that circle. Results outside the defined area may still be displayed. "
Taken from:
https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests
I need to find out in what country given GPS coordinates are, on a device that has no Internet access (e.g. this, but without the easy on-line solution). Having no experience with GIS, I guess I'd need some kind of module that would statically store shapes of countries and match current location against them.
I'd therefore like to ask what kind of tools would be best for this, and what is the best way to obtain the country data. I'm using Python on an embedded Linux box.
There's a shape file here with all of the country borders. You can then use OGR or something like this to access the data.
You might have a look at the GeoDjango documentation even if you aren't making a web application. The tutorial covers importing the world boundaries shapefile.
Have you seen https://github.com/krisrak/ios-offline-reverse-geocode-country/?
all offline ... no need for any APIs super fast .
accuracy not guaranteed !!
You would need a map with the boundaries of each country. Then, given a coordinate, you would need to calculate in which boundary the point fell. Of course, the two challenges there are collecting the data and representing it, and doing the math to find where a point falls.
Does anyone know how Yahoo does it? Could you possibly port their approach locally?
After searching SO and multiple articles I haven't found a solution to my problem.
What I am trying to achieve is to load 20,000 markers on Google Maps.
R-Tree seems like a good approach but it's only helpful when searching for points within the visible part of the map. When the map is zoomed out it will return all of the points and...crash the browser.
There is also the problem with dragging the map and at the end of dragging re-running the query.
I would like to know how I can use R-Tree and be able to achieve the all of the above.
As noted, R-Tree won't help you when you're looking at a zoomed-out view. This problem is often addressed by marker clustering, because showing 20,000 points in a browser window isn't that useful.
Marker Manager is an open source javascript library which addresses this, but there are others.
With a very great number of markers, you may need to look at server-side clustering, (where R-Tree may come in handy!). Here is one discussion of it, and its google cache because link is dead at time of writing.
If you don't want to bother with clustering, then just terminate your marker list at a preset number, maybe a few hundred (which you can determine by usability testing), and display some indication that there are more available as you zoom in
After experimenting with client side approach to clustering large numbers of Google markers I decided that it won't be possible for my project (social network with 28,000+ users).
Are there any examples of clustering the coordinates on the server side - preferably in Python/Django?
The way I would like this to work is to gradually index the markers based on their proximity (radius) and zoom level.
In another words when a new user registers he/she is automatically assigned to a certain 'group' of markers that are close to each other thus increasing the 'group's' counter. What's being send to the server is just a small number of 'groups'. Only when the zoom level/scale of map is 1:1 - actual users are shown on the map.
That way the client side will have to deal only with 10-50 markers per request/zoom level.
This is a paid service that uses server-side clustering, but I'm not sure how it works. I'm guessing that they just use your data to generate the markers to be shown at each zoom level.
Update: This tutorial demonstrates a basic server-side clustering function. It's written in PHP for the Static Maps API, but you could use it as a starting point.
You might want to take a look at the DBSCAN and OPTICS pages on wikipedia, these looks very suitable for clustering places on a map. There is also a page about Cluster Analysis that shows all the possible algorithms you can use, most would be trivial to implement using the language of your choice.
With 28k+ points, you might want to skip django and just jump into C/C++ directly, and surely not expect this to get calculated in real-time in response to web requests.
One way to do it would be to define a grid with a unit size based on the zoom level. So you collect up all the items within a grid by lat,lon to one decimal place. An example is 42.2x73.4. So a point at 42.2003x73.4021 falls in that grid cell. That cell is bounded by 42.2x73.3 and 42.2x73.5.
If there are one or more points in a grid cell, you place a marker in the center of that grid.
You then hook up the zoomend event and change your grid size accordingly, and redraw the markers.
http://code.google.com/apis/maps/documentation/reference.html#GMap2.zoomend
You can try my server-side clustering django app:
https://github.com/biodiv/anycluster
It prvides a kmeans and a grid cluster.