I've built some web crawlers to gather information about Hijacking Hotspots in South Africa... I've retrieved location information, but its all listed in a vague format, e.g.: "The William Nicol Drive offramp from the N1 from the Sandton side" ... Each location is formatted in JSON format right now.
My Problem:
I want to iterate through a list of all these descriptions/locations and retrieve rough GPS coordinates for each one. Would using the Google API with Javascript be the best option for achieving this? And does anyone have some code examples to demonstrate how I should go about getting this done with Javascript. Please keep in mind that I'm only an intermediate Javascript coder.
I need the quickest most efficient method of getting this done because I'm on a tight deadline and I'll have to use this method for a few other purposes as well.
Sample JSON Data:
{"data":{"area":"Cape Town","location":"Corner of Alice St and Voortrekker Road", "gps":"?"}}
It would be great if you can provide a sample of your JSON response.
The Getting Started page for Maps API have samples that will guide you through the whole process of what you want to develop.
The easiest way to do it is if the JSON response you have have lat/long coordinates. This way, you iterate through the items and place Markers to the map.
If no coordinates are available, but there's a placeId on the response, you can try out the Places API. You'll just need to provide the placeId in PlacesService.getDetails() and the response will contain an object with the lat/long coordinates - which you'll add into the marker.
Related
Let me begin by saying, I have been searching for resources for this question for more than 3 days, so I truly hope I did not miss an "answer" anywhere.
Background:
I am working on a website/app built in HTML/CSS/Javascript that will use geolocation (Google Maps & Places API) to find a users location and return them the (for example) top 5 closest water parks to them at that location they are currently at.
Question:
I want to control the list of results the API picks from. So let's say, it'll only give them 5 out of 30 water parks that are near them and I have previously specified the names/locations of those 30 water parks.
The reason I want to do this is because after searching via Google Maps for "water parks nearby 123 Main Street, City, State" - it doesn't return all the results I want it to, just some.
As I stated, I have looked far and wide for this answer. I have read almost all of the relevant Google Places API and Maps API documentation with no clear cut answer. I have also found a few website that let you use a Google Docs spreadsheet to specify locations, but you can't get the code from them. And I have seen a few example using XML, but nothing exactly what I'm looking for.
I will also note that I am familiar with C# and PHP if that helps get me closer to my goal. But it seems like Javascript is the way to go.
Any help/hints/tips would be greatly appreciated! Thanks!!
Store the data in a database that supports spatial queries(may be a FusionTable for example), then you may use ST_DISTANCE to order the results by distance and LIMIT to limit the resultset.
I'm trying to implement a Google Map.
Part one is centering the map to a specific address, which works quite nice.
My next problem is that I have to place a marker for a store on the map, based on a search on the store name. The marker should probably be connected to a search result in order to display a info bubble when clicked. How to get about and do this, I'm totally qlueless about.
Your steps seem ok to me, I assume that the search for store name goes to your server and you return some result with store names and addresses, then you look that up using Google Geocoding API and fetch the lat/lng coordinates and place the markers on the map, here are the steps that I would probably use:
Create a map
Center on a specific address
Search for a store
If the result has geocode associated with it then just use that to place a marker.
If the result does not have lat/lng then make a request to Google Geocoding API to get the lat/lng coordinates. After that place the marker, store the received geocode to your database (by using some background Ajax request).
The Google Geocoding API best practices suggest that you should store the geocodes so that you don't have to query each time to Google's servers. In order to do that you will need to modify your backend so that it also stores Geocode along with the store details, and in search result you can return the geocodes if available.
On a side note, you can use GMaps JavaScript library for easy map manipulation.
Update
The above solution works perfectly in your revised scenario. Let me rephrase the flow again:
The backend would return a list of stores when searched by a store name (this should be pretty easy I guess)
If results are not empty then loop through the list and see if all of them has a lat/lng value associated with.
If you do not find a lat/lng value for a record then make a Geocode request to Google's server passing the address of the store (you need to have at least the address of the store else you can't get the lat/lng value from Google) as a parameter. If the record has a lat/lng value then just go ahead and place a marker on the map.
Once you receive the response from Geocode API then go ahead and place a marker on the map using the maps library API as provided. For GMaps it is map.addMarker({...}).
Once all the the requests are complete then you can consider optimizing a bit which was suggested earlier where you can store the received geocodes in your own server, so that you don't have to fetch them again and again.
To implement the above steps you need to have familiarity with the Maps JS library as well as JavaScript and Ajax/JSONP. Remember that all your Geocode requests(JSONP I think) are asynchronous and you should invoke the marker placement code only when the response is available to you (typically inside a callback). The GMaps library examples are very easy and simple to start with. I hope this explanation should be enough to solve your problem and if it helps you then you can consider marking this an answer.
Im working with the google-mapquest mapping API. I need to add some Points of Interest near a certain area from a given latitude-longitude location.
I search the google and mapquest documentation to figure out if there is a method to get all zip-codes in that area but i didnt find anything that does that.
I tried the harvesine implementation to calculate the nearest point given in that radiuos/latitude-longitude and it works fine. The problem with this approach is that i need to update constatntly the database, so i dont like it much.
The question is: Is there a service (google-mapquest or another) that gives you this information?.
No, there is no API for either service that I am aware of. Your best bet is to just get a ZIP Code database and use that. Some really good inexpensive ones are out there. I prefer http://www.zip-codes.com/zip-code-database.asp. Their $40 package is very accurate, updated monthly, and licensed by the USPS (so you know it's quality data).
UPDATE:
I found a WebService that does exactly what i need. You could provide only a simple ZipCode and a country or perhaps a full address and in the response you get the longitude/latitude. Then i send the Latitude and Longitude returned to get a list of all the ZipCodes near the provided coordinates and a given Radius that also can be customized.
You can filter the total rows you want the service to return, or even if you are gonna use miles or kilometers as the measure unit.
So, basically with the returned information, i feed those coordinates for each of the nearest ZipCodes obtained to the google API and render those points of interest into the map that you need to show.
The services are provided by GeoNames. Its an organization dedicated to Geolocalization services. They offer also premium data, but in particular these services are free of use, obviously the information is not as accurate as the premium one, but actually in my tests i found that that is trustful and the response also is very fast.
Another good advantage is that the process to get a Key for use Geonames services it's quite simple.
I left you the link of the services that i'm talking about.
List of available services:
http://www.geonames.org/export/web-services.html
Hope it helps many people.
Regards!
I am looking for a javascript library that supports the ability to pass a zipcode or city as a parameter, and get a list of x,y coordinates to draw a polygon using google maps?
Does this exist? Does the google maps API support such queries? I am looking for an array of coordinates similar to those that google uses to draw maps on a google query:
Google Maps API doesn't support that kind of solution. There are a couple other places from which you can get the coordinates, though:
Flickr API
There is a Flickr API based on photos that people tag, but it's only as accurate as the people who tag photos: so it's good enough for bootstrapping but probably not for production: http://karya-blog.blogspot.com/2012/12/fetching-city-polygons-with-flickr-api.html
Natural Earth Data
An accurate alternative is www.naturalearthdata.com. To get that data from there you just need to make two requests: one with the city name and one with their ID to get the parameters:
unlock.edina.ac.uk/ws/search?name=berlin&gazetteer=naturalearth&format=json
and then
unlock.edina.ac.uk/ws/footprintLookup?format=json&identifier=14126951
and you're set :)
Mapzen
If it's possible for you to pre-fetch the data, go for Mapzen, they have a full and pretty accurate database: https://mapzen.com/data/borders/
Short answer: I do not think there is any magical getZipCodeBoundaries method in the Google Maps API. However, what you want to do can and has been done. Please see the implementation, and this thread on Google groups concerning the process. Is the first link similar to what you're hoping to accomplish? Also, there is a neighborhood API offered from Zillow under the CC license. You might want to look into that and see if it breaks neighborhoods down by zipcode.
You can get polygon coordenates in json for using with googlemaps using openstreetmap.
Go to http://nominatim.openstreetmap.org/
search a place like "Partido de Ituzaingó"
Steps:
Click on "details"
Look for the OSM ID and copy it (control+c), example: 2018776
Go to http://polygons.openstreetmap.fr/index.py
Paste the ID in
Download the polygon
Look on this site Twitter geo api You have few modes of search, and it gives You boundary box for cities. I am using it now on My site. Try f.e. this link and U will see the results.
My client has a list of store locations. Now what he wants is to let users search for any of these locations, based on the address the user submitted. The search results will be based on the proximity of the locations.
So basically what I am looking for is Google Maps functionality, but based only on the set of (geographical) data I provide.
Do any of you know if this is even possible, and if so, what can be a good starting point to learn more about it?
Thanks in advance.
Sure it is possible. I guess you have in you database set of the latitude and longitude entries for each store. You can get users current location with geocoder and measure distance with distanceFrom call to find the nearest store.
You're welcome to copy the code directly from here, it does exactly what you request.
You'll need offices.htm, offices.js and logo.png.
To prepare your list of offices, you might find this Excel addin useful