The idea is simple, but I can't find information or examples. I want that the user to draw a route in the map and then be capable of getting the info of locations and addresses in data structure like an array, or json.
http://code.google.com/apis/maps/documentation/javascript/examples/polyline-complex.html
The above link is an example of what you're looking for, have a look at the source code it seems pretty straight forward. This example is for Google Maps api v3
You can retrieve the points using the Polyline,getPoints() method.
Related
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.
I am working with the here maps api doing some routing between two points.
I can calculate the route and show the maneuvers to the user but I cannot get the maneuver icon. In the previous api, there was a javascript function getIcon, but that has been removed from the most resent api (2.5.4).
When I take a look at here.com and perform the routing between the two points, I can find the js function in there, but the function is not in the 2.5.4 version of the api.
(I cannot upgrade to v 3 of the api at this point in time, so I don't know if that will help)
What can I do when using v2.5.4 of the api to get the maneuver icon to show it to my users?
Below is a sample screen snip from here.com on the images I am referring to.
The Turn symbols are not part of the API, you can use in the Maneuvers the "direction" and "action" properties to draw your own symbols.
Was this ever exposed in the API?
Just looked through the compressed code and I don't find that symbol anywhere...
Anyways, I believe the last resort is to map the "action" property in the maneuvers to your own images (or an image sprite similar to the one on here.com ;). The possible values of the action property are documented here:
https://developer.here.com/rest-apis/documentation/routing/topics/resource-type-enumerations.html#resource-type-enumerations__enum-private-transport-action-type
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.
I'm using Google Maps API to visualize some label on the map using google.maps.Polygon. I used this converter http://converter.mygeodata.eu/ to convert them in a GeoJSon format, but latitude and longitude coordinates where mistaken.
They should be centered in Florence, Italy, but actually i get this:
1680508.8375
4847672.484
I tried tho divide them by 10000 and i got:
16.805088375
48.47672484
wich alow me to show some results, but that was not the results I was looking for (I get them displayed in Austria instead of Florence)
Surfing the net I found this https://groups.google.com/forum/?fromgroups#!topic/d3-js/H0zE7slqV0g that describe my problem and find a solution using d3.
Is there any way to do that just with google maps API and/or using some conversion?
Thanks
Ok seems that I found what the problem is. There are many different way to locate a point in a map. Google Maps uses a WGS84 encoding, but i got the data in EPSG:3003 encoding. So they didn't match.
I was able to find a js library that makes all the conversion you need.
http://trac.osgeo.org/proj4js/
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.