Rails Finding towns within a 10 mile radius of postcode. Google maps API - ruby-on-rails

I'm using the geocoder gem and was wondering if there is a way to get all cities within a radius (with center coordinates).
Something like
city = location.cities(100) #all cities within 100km
There seems to be a PHP solution, but I'm not sure how it can be used in my case.
Thanks!

I don't believe GoogleMap API offers spatial search. Geonames.org site publishes such a Web service -- the associated Geonames gem doc has a specific example for finding places near a lat/long point:
places_nearby = Geonames::WebService.find_nearby_place_name 43.900120387, -78.882869834

Related

Get random address/coordinates in a specified town

Is there any way to give Google Maps API or a similar API a town name and have it return a random address inside the town? I was hoping to be able to get the data as a JSON so I could parse it with SwiftyJSON in XCode and use it, but I can't seem to find any way to get the address in the first place. If coordinates would be easier to get, then those would work too, as long as its random and inside the town borders.
You can try to use Google Places API Web Service. It allows you to query for place information on a variety of categories, such as: establishments, prominent points of interest, geographic locations, and more. You can search for places either by proximity or a text string. A Place Search returns a list of places along with summary information about each place.
A Nearby Search lets you search for places within a specified area. You can refine your search request by supplying keywords or specifying the type of place you are searching for.
A Nearby Search request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
where output may be either xml or JSON values.
And if you want either address or coordinates, you can use Geocoding for it. Here i found a tutorial on how to use Geocoding in IOS.

iOS: Getting Cities/Counties between Start Location and End Destination Using Google Map or Directions API

Hi Experts and Friends,
I have been searching for a solution for this seemingly simple task for days already, but I don't seem to have come across any useful approach.
Here is what I want:
Get my current location using CLLocation (ok here)
Get the final destination I enter (also ok here)
What I would like to accomplish is: get a list of cities in between these two points.
If the start location lies within the same city limit of the end destination, then simply show only that city in which the start location is.
EX: Current Location SF
Destination: Cupertino
Cities in between: Daly City, San Bruno, etc etc ....Santa Clara....Cupertino.
Is it possible to grab these from Google APIs? And am not talking about the "steps", because many steps can lie within a city limit, am only interested in cities (or county).
If so, which (v2.? v.3?) one? Or from Directions API? How are they different by the way? Am asking because different people seem to have different answers.
Thanks in advance. Regards.

Given longitude and latitude, how to find country

If I have a latitude and longitude, how do I find out the country of that location..
If found out about Google Reverse Geocoding, but unfortunately, it requires the service to be used along with Google Maps, which is not my case..
Is there a static database or something which I can refer to? It would be better if I have a static database as opposed to a service..
Without a service, it is a lot of work.
First, you need the country polygons with assigned country codes. One country will have on average approx 50.000 vertices.
Then it's a simple point-in-polygon search.
Use a spatial index to limit the country polygon to search.
It becomes a bit more difficult if you have to consider enclaves.
You can use Bing Maps Api, it doesn't require displaying maps as far as I know,
http://dev.virtualearth.net/services/v1/geocodeservice/geocodeservice.asmx/ReverseGeocode?latitude=22.98&longitude=35.43637&key=[YOU_KEY]&culture=%22en-us%22&format=json
You can use the geonames.org "Country code / reverse geocoding" webservice, for example:
http://api.geonames.org/countryCode?lat=47.03&lng=10.2&username=demo
-> AT

How to get nearby location on google maps give a lat and lng coordinates

I wish to know how to get nearby location over a certain range of radius.
For example I have location of stores data stored in the database, and I want to search for a coffee over a range of 25 radius or 40 radius or even more, from a given lat and lng coordinate and then display them with their various distance from this lat and lng coordinate. I saw an example on Google but it's not working.
I would do the requested app as follows , i realize there are other ways to do it, i try:
would first go to Google code playground and get sample for the geo location.
rewrite the java script function so that it takes the longitude and latitude as parameters.
include the html file in your project , then create a webbrowser control in your csharp app.
then call the navigate to local page which will launch the page with the given longitude and latitude
You may use iFreeTools Creator - an online database app builder over Google App Engine - to store and search the geo-location database.
For a step-by-step guide on how you can do this, refer to the following blog post..
Building a Store Locator type Google Maps app over GAE, using iFreeTools
// Disclosure : I wrote code for this web-app.

City By GPS Location Latitude/Longitude

I've got a latitude/longitude value.... How can I search and get the city?
If you're looking for free (as freedom) sources, you can use Geonames API findNearbyPlaceName.
For example the following returns nearest Placename:
http://api.geonames.org/findNearbyPlaceName?lat=47.3&lng=9&username=demo
More information is available here
http://www.geonames.org/export/web-services.html#findNearbyPlaceName
Another option is getting data from Freebase. Instead of single point it takes bounded box:
http://api.freebase.com/api/service/geosearch?location=[30.2,50.4,30.6,50.8]&location_type=/location/citytown&inside=true&indent=1
Using the google maps api, here is an example to get the address in XML format.
http://maps.google.com/maps/api/geocode/xml?latlng={latlng}&sensor={sensor}&region={region}
Where latlng = 0,0 sensor = false, and region = country code, so for my old address it would be
http://maps.google.com/maps/api/geocode/xml?latlng=-43.893792,171.7592620&sensor=false&region=nz
Then you can use that XML to get whatever details you need, including the City

Resources