I've encoded a polygon's path.
When I check it in https://developers.google.com/maps/documentation/utilities/polylineutility, it works perfectly :
Polygon in Google Devlopper Test
encoded path: wptdHtgeI#a#HaEHmCTkDDUVsAF{G#wD#o#~~~~~~Bq##{CAuC?{D?_B?e#EsCe#aCoA{Ea#}AOm#vAgA|BcBr#i#nCs#hBe#~#UlFmAZI|Cs#nBc#FAf#K`#IAvDFF~~~~~~Bp##|D~~~~~~BlC#tG~~~~~~BX#hG~~~~~~B`A~~~~~~BzC~~~~~~BfB~~~~~~Bx#~~~~~~B|D~~~~~~B^~~~~~~BtA#`D~~~~~~B`#~~~~~~B~~~~~~BG?B\?bE~~~~~~BrD#jJ#xDEvA~~~~~~Bt#?rA#|F?|E~~~~~~BRIBq#JC#k#Hm#H?~~~~~~BA~~~~~~B#Pq#\{Av#sBbA{ADk#Xi#Hi#G[GUIUGUIMC_EwBWCYEUC~~~~~~B?HiC|#LF#F}#BWNaDNsDc#YuABU#sADH_D~~~~~~BAYFB{#??
But when I try the same code with a static map, i doesn't work.
I changed the path with urlencode in PHP :
https://maps.googleapis.com/maps/api/staticmap?key=YOUR_API_KEY¢er=48.109115,-1.670599&zoom=13&size=600x600&maptype=roadmap&path=fillcolor:0xAA000033%7Ccolor:0xFFFFFF00%7Cenc:wptdHtgeI%40a%40HaEHmCTkDDUVsAF%7BG%40wD%40o%40%7E%7E%7E%7E%7E%7EBq%40%40%7BCAuC%3F%7BD%3F_B%3Fe%40EsCe%40aCoA%7BEa%40%7DAOm%40vAgA%7CBcBr%40i%40nCs%40hBe%40%7E%40UlFmAZI%7CCs%40nBc%40FAf%40K%60%40IAvDFF%7E%7E%7E%7E%7E%7EBp%40%40%7CD%7E%7E%7E%7E%7E%7EBlC%40tG%7E%7E%7E%7E%7E%7EBX%40hG%7E%7E%7E%7E%7E%7EB%60A%7E%7E%7E%7E%7E%7EBzC%7E%7E%7E%7E%7E%7EBfB%7E%7E%7E%7E%7E%7EBx%40%7E%7E%7E%7E%7E%7EB%7CD%7E%7E%7E%7E%7E%7EB%5E%7E%7E%7E%7E%7E%7EBtA%40%60D%7E%7E%7E%7E%7E%7EB%60%40%7E%7E%7E%7E%7E%7EB%7E%7E%7E%7E%7E%7EBG%3FB%5C%5C%3FbE%7E%7E%7E%7E%7E%7EBrD%40jJ%40xDEvA%7E%7E%7E%7E%7E%7EBt%40%3FrA%40%7CF%3F%7CE%7E%7E%7E%7E%7E%7EBRIBq%40JC%40k%40Hm%40H%3F%7E%7E%7E%7E%7E%7EBA%7E%7E%7E%7E%7E%7EB%40Pq%40%5C%5C%7BAv%40sBbA%7BADk%40Xi%40Hi%40G%5BGUIUGUIMC_EwBWCYEUC%7E%7E%7E%7E%7E%7EB%3FHiC%7C%40LF%40F%7D%40BWNaDNsDc%40YuABU%40sADH_D%7E%7E%7E%7E%7E%7EBAYFB%7B%40%3F%3F
Please : I need a solution with PHP and not js, and for STATIC maps only...
There seems to be an issue with your encoded path. Use the resulting encoded polyline from the Interactive Polyline Encoder Utility on your Static Maps API request.
Given your encoded path,
wptdHtgeI#a#HaEHmCTkDDUVsAF{G#wD#o#~~~~~~Bq##{CAuC?{D?_B?e#EsCe#aCoA{Ea#}AOm#vAgA|BcBr#i#nCs#hBe#~#UlFmAZI|Cs#nBc#FAf#K`#IAvDFF~~~~~~Bp##|D~~~~~~BlC#tG~~~~~~BX#hG~~~~~~B`A~~~~~~BzC~~~~~~BfB~~~~~~Bx#~~~~~~B|D~~~~~~B^~~~~~~BtA#`D~~~~~~B`#~~~~~~B~~~~~~BG?B\?bE~~~~~~BrD#jJ#xDEvA~~~~~~Bt#?rA#|F?|E~~~~~~BRIBq#JC#k#Hm#H?~~~~~~BA~~~~~~B#Pq#\{Av#sBbA{ADk#Xi#Hi#G[GUIUGUIMC_EwBWCYEUC~~~~~~B?HiC|#LF#F}#BWNaDNsDc#YuABU#sADH_D~~~~~~BAYFB{#??
you'll have following encoded polyline from the Interactive Polyline Encoder Utility which you can use on your Static Maps API request:
wptdHtgeI#a#HaEHmCTkDDUVsAF{G#wD#o#?q##{CAuC?{D?_B?e#EsCe#aCoA{Ea#}AOm#vAgA|BcBr#i#nCs#hBe#~#UlFmAZI|Cs#nBc#FAf#K`#IAvDFF?p##|D?lC#tG?X#hG?`A?zC?fB?x#?|D?^?tA#`D?`#??G?B\?bE?rD#jJ#xDEvA?t#?rA#|F?|E?RIBq#JC#k#Hm#H??A?#Pq#\{Av#sBbA{ADk#Xi#Hi#G[GUIUGUIMC_EwBWCYEUC??HiC|#LF#F}#BWNaDNsDc#YuABU#sADH_D?AYFB{#??
You can try this working API request:
https://maps.googleapis.com/maps/api/staticmap?key=YOUR_API_KEY¢er=48.109115,-1.670599&zoom=13&size=600x600&maptype=roadmap&path=fillcolor:0xAA000033%7Ccolor:0xFFFFFF00%7Cenc:wptdHtgeI#a#HaEHmCTkDDUVsAF{G#wD#o#?q##{CAuC?{D?_B?e#EsCe#aCoA{Ea#}AOm#vAgA|BcBr#i#nCs#hBe#~#UlFmAZI|Cs#nBc#FAf#K`#IAvDFF?p##|D?lC#tG?X#hG?`A?zC?fB?x#?|D?^?tA#`D?`#??G?B\?bE?rD#jJ#xDEvA?t#?rA#|F?|E?RIBq#JC#k#Hm#H??A?#Pq#\{Av#sBbA{ADk#Xi#Hi#G[GUIUGUIMC_EwBWCYEUC??HiC|#LF#F}#BWNaDNsDc#YuABU#sADH_D?AYFB{#??
Note: Please provide your own API key on the sample request.
Hope this helps!
Related
They seem to work much in the same way but I can't figure out the difference.
loadGeoJson takes a URL
from the documentation
loadGeoJson(url:string, options?:Data.GeoJsonOptions, callback?:function(Array))
Return Value: None
Loads GeoJSON from a URL, and adds the features to the collection.
addGeoJson takes GeoJSON
from the documentation
addGeoJson(geoJson:Object, options?:Data.GeoJsonOptions)
Return Value: Array
Adds GeoJSON features to the collection. Give this method a parsed JSON. The imported features are returned. Throws an exception if the GeoJSON could not be imported.
in graphhopper the points are encoded then decoded in javascript
but i'd like to have the points not encoded, how is it possible ?
is there a php alternative of the decodePath(encoded, is3D) function ?
thanks
There is only a Javascript and Java version at the moment in GraphHopper but it shouldn't be hard to write one in PHP. Or see the docs on how to disable encoded polylines.
I have an issue whith google maps directions service (api v3). I don't know how specify the origin and destination strings. For example for the requests:
http://maps.googleapis.com/maps/api/js?sensor=false®ion=ES&languaje=es&key=xxxxxxxxxxxxx&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010"
or
http://maps.googleapis.com/maps/api/directions/xml?sensor=false®ion=ES&languaje=es&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010"
the response of the server is: NOT_FOUND, ie route not found,
however if I change the character Ñ by N, ie ESPAÑA by ESPANA the response is OK.
There are other places with "especial characters" for example: Göttingen, München, Köln, ....
I have been looking for information in the documentation but can not find anything about.
How can I specify the different origins and destinations?
Regards,
Francisco
Request http://maps.googleapis.com/maps/api/directions/xml?sensor=false®ion=ES&languaje=es&origin="EJIDO+EL,ESPAÑA,04700"&destination="CORCOLLE,ITALIA,00010" is true, you can test it in browser.
If you have issue in request maybe it come from URL Encoding. With special character in string URL you need encode it before do request with this string
I developed an app that sends GPS points to a server and the server convert those GPS points into a path, which is shown in a map.
Now the server makes a call to Google Maps Directions service and gets a response. From that response I use the value overview_polyline, which based on the documentation:
Contains an object holding an array of encoded points that represent
an approximate path of the resulting directions.
The problem is that sometimes the line I get is really weird. Sometimes it gives me a path where there's no street at all.
Here are some screenshots to describe my problem. The yellow marker is the start point (A), and the blue marker is the end point (B).
So I asked Google to give a route from A to B, with driver mode, so it shows the actually path.
And this is the result:
This is the API call I use. My question is: Any idea why would it return that path?
http://www.geocodezip.com/v3_example_geo2.asp?addr1=53%20Imperial%20Avenue,%20Westport,%20CT%2006880,%20USA&addr2=2%20Harborview%20Road,%20Westport,%20CT%2006880,%20USA&geocode=1&geocode=2&type=m
Looks to me like the encoded polyline is not being rendered correctly. How is your code handling that?
example using the geometry library decodePath function
Looks to me like Google broke their polyline encoding.
If I paste it into here (which admittedly doesn't expect polylines, it expects polyons)
I need to escape the "`", change:
{pazFraw~L|#|#f#^`#N\\?XIx#a#n#[
to:
{pazFraw~L|#|#f#^\`#N\\?XIx#a#n#[
to make it have a more reasonable shape.
I use such urls like:
http://maps.google.com/?saddr=546%206th%20Avenue,%20New%20York,%20NY%2010011%20(Sixth%20Avenue,%20New%20York)&daddr=W%20103rd%20St,%20New%20York,%20NY%20&dirflg=r
But it returns full html page. Does anybody know how to get such info in json or xml or any parsable format?
I need public transit.
You just add &output=json to the end of the url.
I'd like to extend Mathias's answer a little bit.
There's no official Google Transit API at the momemnt. Transits are provided by agencies, and most of Transits are not public. So, Google is not allowed to open them as API.
You may try to consume the "unofficial" data using your link + "&output=json".
However, the result won't be a valid JSON. Instead, that's something, that can be easily converted to a JavaScript object. (The differences are: there is no quotes around property names,
the strings are not properly encoded etc.)
Imagine you got this JavaScript object. However, it won't allow you to easily get the structured route details. Object's properties contain the route points coordinates, but no descriptions. The only place where the descriptions may be found is 'panel' property, which contains a chunk of HTML text (you may find a link to the sample of HTML in my blog post)
So, you'll have to convert this HTML into XML (X-HTML) and then build the parser of this XML to get the essence data of a trip.
Seems like a bit of overkill to me. Having in mind, that "unofficial" API may change in the future, including slight changes in 'panel' HTML structure that will kill your parser.
#MathiasLin, how did you overcome this?
Google Maps Javascript v3 and the Directions Web Service now has this capability as per :
https://googlegeodevelopers.blogspot.in/2012/06/public-transit-routing-and-layer-now.html
Update:
Latest server side API docs:
https://developers.google.com/maps/documentation/directions/get-directions
Re choosing public transport - it seems that it defaults to public transport now (at least when I use it).
Changing the last URL parameter, dirflg=r, into dirflg=w switches the directions to walking mode.
Plus see:
Walking, bicycle and public transport directions with time required in each mode , iPhone
for more detail about the parameters.
Google direction API response is in HTML, JSON format please check https://developers.google.com/maps/documentation/javascript/directions?hl=lv
& section 'The DirectionsResult Object'