Google Maps API - retrieve my markers? - google-maps

Sorry if this question ends up being obvious to some. Suppose I have manually created a map on Google Maps: I have added a few markers at specific coordinates, each one has a description associated. Now, is there an endpoint in the Google Maps API that lets me execute a query to retrieve data about all the markers? Maybe something that would return a list of markers like
{
...,
"markers" : [
{
"name" : "London",
"lat" : 12.34,
"lng" : 56.78
},
{
"name" : "Paris",
"lat" : 98.76,
"lng" : 54.32
}
]
}
I am aware that those are not the real coordinates of London and Paris :) Thanks!

Answer: there is no way to do this.

you could get some information with a reverse geocode lookup
What type of information are you looking to get?
I recommend taking a look at the api documentation

Related

Google Maps Find Place API locationbias causing zero results

I am trying to use the locationbias feature of the Find Place API to provide more relevant results for my searches. I have tried both a point and a rectangle, and in both cases my query returns zero results. However, if I remove the bias completely I do get a result. Why is a location that I know is within the boundary of the rectangle not being returned? Also, the field is called locationbias implying it will prefer Places near this location but not force strict boundaries, so why am I getting zero results?
Here is an example GET: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Ariel%20Dunes%201%20Unit%20308%20Seascape%20Resort&inputtype=textquery&locationbias=rectangle%3A30.119056%2C-86.527098%7C30.444872%2C-85.705723&fields=geometry%2Flocation%2Cname%2Cplace_id
Response:
{ "candidates" : [], "status" : "ZERO_RESULTS"}
Without locationbias: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?inputtype=textquery&fields=geometry%2Flocation%2Cname%2Cplace_id&input=Ariel%20Dunes%201%20Unit%20308%20Seascape%20Resort
Response:
{ "candidates" : [ { "geometry" : { "location" : { "lat" : 30.377608, "lng" : -86.366795 } }, "name" : "Ariel Dunes I (ADI) at Seascape Resort", "place_id" : "ChIJF5B7IoRbkYgRQWjAZv0-wUI" } ], "status" : "OK" }
For clarity, here's the decoded locationbias used above: rectangle:30.119056,-86.527098|30.444872,-85.705723
According to the docs this should be the southwest corner of the rectangle followed by the northeast corner of the rectangle.
The issue was due to my use of Postman. Postman implicitly encodes the query string. Disabling this feature allowed me to use a literal colon between the shape and the coordinates which corrected the behavior.

Decoding the Google Maps embedded parameters

The context
I would like to be able to extract the location of Google Maps embedded in a website (random example found at the bottom of this website).
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3128.340699934565!2d-0.46482818466529047!3d38.3642391796565!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd62377123a70817%3A0x85e89b65fcf7c648!2sCalle+Cruz+de+Piedra%2C+4%2C+03015+Alicante!5e0!3m2!1ses!2ses!4v1476192292052" width="100%" height="350" frameborder="0" style="border:0" allowfullscreen=""></iframe>
So, basically I want to extract the pinpoint location from the Maps URL:
https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3128.340699934565!2d-0.46482818466529047!3d38.3642391796565!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd62377123a70817%3A0x85e89b65fcf7c648!2sCalle+Cruz+de+Piedra%2C+4%2C+03015+Alicante!5e0!3m2!1ses!2ses!4v1476192292052
The URL design
Google seems to use a proprietary parameter design here. This blog entry and this Stackoverflow post did a good job summarizing how these parameters can be understood. The parameters are structured like (![id][type][value]), with types:
m: matrix
f: float
d: double
i: integer
b: boolean
e: enum (as integer)
s: string
u: unsigned int
Matrices can encapsulate multiple data entries, e. g. !1m3!1i2!1i4!1i17 means that the matrix with the ID 1 contains the three integer values [2, 4, 17].
With this knowledge, the parameters can be structured like this:
!1m18
!1m12
!1m3
!1d3128.340699934565
!2d-0.46482818466529047
!3d38.3642391796565
!2m3
!1f0
!2f0
!3f0
!3m2
!1i1024
!2i768
!4f13.1
!3m3
!1m2
!1s0xd62377123a70817:0x85e89b65fcf7c648
!2sCalle Cruz de Piedra, 4, 03015 Alicante
!5e0
!3m2
!1ses
!2ses
!4v1476192292052
Now it seems to be easy, we see coordinates almost in clear-text. But as the blog entry points out, the parameters
!1d3128.340699934565
!2d-0.46482818466529047
!3d38.3642391796565
are not the position of the pinpoint, but the center of the shown map. They are similar, but at times very different. Changing the coordinates and/or the address will not result in a different map.
Only when changing the parameter !1s0xd62377123a70817:0x85e89b65fcf7c648, the map display will break, meaning this parameter decodes the location of the pinpoint.
Just, in what encoding?
The question
In the blog entry (from August 2016), the Maps link is built up differently. There is another parameter which encodes the longitude and latitude coordinates in base64:
zMzfCsDQ3JzM0LjUiUyAxNDXCsDAwJzU2LjYiRQ ----base64---> 37°47'34.5"S 145°00'56.6"E
In a similar manner, the coordinates of this new parameter should hopefully decode:
0xd62377123a70817:0x85e89b65fcf7c648 ----????----> 38.364236,-0.462649
It looks like hexadecimal encoding, but when converting to integer (964394229279688727:9649133063979386440), this does not correspond to geographic coordinates in a system I know.
So, who can crack the code? Any help appreciated.
This intermediate is not the final answer, and the sequel follows)), just some thoughts
Undocumented method. (with ftid instead of place_id parameter)
Places API Web Service
No warranty in future:
https://maps.googleapis.com/maps/api/place/details/json?key=YOUR_API_KEY&ftid=0xd62377123a70817:0x85e89b65fcf7c648&
The documented request is:
https://maps.googleapis.com/maps/api/place/details/json?key=YOUR_API_KEY&placeid=ChIJFwinI3E3Yg0RSMb3_GWb6IU
Need API KEY for this requests Setting up API keys
Answer from Google: (JSON - light parsing)
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "4",
"short_name" : "4",
"types" : [ "street_number" ]
},
{
"long_name" : "Calle Cruz de Piedra",
"short_name" : "Calle Cruz de Piedra",
"types" : [ "route" ]
},
{
"long_name" : "Alacant",
"short_name" : "Alacant",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Alicante",
"short_name" : "A",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Comunidad Valenciana",
"short_name" : "Comunidad Valenciana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Spain",
"short_name" : "ES",
"types" : [ "country", "political" ]
},
{
"long_name" : "03015",
"short_name" : "03015",
"types" : [ "postal_code" ]
}
],
"adr_address" : "\u003cspan class=\"street-address\"\u003eCalle Cruz de Piedra, 4\u003c/span\u003e, \u003cspan class=\"postal-code\"\u003e03015\u003c/span\u003e \u003cspan class=\"locality\"\u003eAlacant\u003c/span\u003e, \u003cspan class=\"region\"\u003eAlicante\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eSpain\u003c/span\u003e",
"formatted_address" : "Calle Cruz de Piedra, 4, 03015 Alacant, Alicante, Spain",
"geometry" : {
"location" : {
"lat" : 38.3642358,
"lng" : -0.4626489
},
"viewport" : {
"northeast" : {
"lat" : 38.3655847802915,
"lng" : -0.4612999197084979
},
"southwest" : {
"lat" : 38.3628868197085,
"lng" : -0.463997880291502
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "ce1aa5a252b86d559268866a6a4858db9bba3dff",
"name" : "Calle Cruz de Piedra, 4",
"place_id" : "ChIJFwinI3E3Yg0RSMb3_GWb6IU",
"reference" : "CmRbAAAAn6NLYXEs-ttLvUlgjnh5aDHt-LR_hXe6JmUN8fzv6MJ7Q50xt_zUU_WlTc3aL_BQc70-1YjEb6Soluro5rA8cIFJG_w08RSr_JWo_SFEFc1Ncme_dKVKsPX6Q0LtO8gWEhACTzabAMLQfM5xt1_BNsywGhSZr0WRGlutqeuRgs-IY41ndk3yoQ",
"scope" : "GOOGLE",
"types" : [ "street_address" ],
"url" : "https://maps.google.com/?q=Calle+Cruz+de+Piedra,+4,+03015+Alacant,+Alicante,+Spain&ftid=0xd62377123a70817:0x85e89b65fcf7c648",
"utc_offset" : 60,
"vicinity" : "Alacant"
},
"status" : "OK"
}
Setting up API keys
If your client application does not use OAuth 2.0, then it must include an API key when it calls an API that's enabled within a Google Cloud Platform project. The application passes this key into all API requests as a key=API_key parameter.
To create your application's API key:
Go to the API Console.
From the projects list, select a project or create a new one.
If the APIs & services page isn't already open, open the left side
menu and select APIs & services.
On the left, choose Credentials.
Click Create credentials and then select API key.
Note: In addition to reading the instructions on this page, be sure to read Best practices for securely using API keys.
(draft) not deleted for history
for test only! temporary solution:
curl "https://www.google.com/maps/place/data=!4m2!3m1!1s0xd62377123a70817:0x85e89b65fcf7c648" -s -b -L -H "user-agent: Googlebot/2.1 (+http://www.google.com/bot.html)" | FIND """0xd62377123a70817:0x85e89b65fcf7c648"","
Answer in command prompt:
,["0xd62377123a70817:0x85e89b65fcf7c648",null,null,[null,null,38.364235799999996,-0.4626489]
CURL there if needed
search to be continued....
I think, this (0xd62377123a70817:0x85e89b65fcf7c648) is ID of map object in GoogleMap database. When click URL1.
For Example
if you want geographic coordinates then click URL2 please and next if need create link as EMBED no problem, result below:
src="https://www.google.com/maps/embed?pb=
!1m18
!1m12
!1m3
!1d782.0856626047412
!2d-0.46311117079625247
!3d38.36419405026406
!2m3
!1f0
!2f0
!3f0
!3m2
!1i1024
!2i768
!4f13.1
!3m3
!1m2
!1s0x0%3A0x0
!2zMzjCsDIxJzUxLjEiTiAwwrAyNyc0NS4yIlc
!5e0
!3m2
!1ses
!2ses
!4v1509474812934"
it is FTID (0xd62377123a70817:0x85e89b65fcf7c648)
The ftid parameter is a unique identifier for certain map objects, just as fid and cid are.
Locations that need to be on the map but are not part of the Local database are identified by the ftid parameter. It is not possible to claim these type of Maps objects through Places.
API Google Places and others work with place-id
for (Calle Cruz de Piedra, 4 03015 Alicante) place-id = ChIJFwinI3E3Yg0RSMb3_GWb6IU
(place -> place-id)
https://developers.google.com/maps/documentation/javascript/examples/places-placeid-finder
and Reverse (place-id->place)
https://developers.google.com/maps/documentation/javascript/examples/geocoding-place-id
NOW:
place-id to location - ok
https://developers.google.com/maps/documentation/geocoding/intro?hl=en#ReverseGeocoding
FTID to location -? question open... for fast and automatic
way over Google:
https://google.com/maps?ftid=0xd62377123a70817:0x85e89b65fcf7c648
https://www.google.com/maps/place/Calle+Cruz+de+Piedra,+4,+03015+Alicante,+%D0%98%D1%81%D0%BF%D0%B0%D0%BD%D0%B8%D1%8F/#38.3642358,-0.4648376,17z/data=!3m1!4b1!4m5!3m4!1s0xd62377123a70817:0x85e89b65fcf7c648!8m2!3d38.3642358!4d-0.4626489
for Atlantic Ocean work too:
https://google.com/maps?ftid=0xadd28c30ec90d79%3A0x44652457c0696504
and two words about Google Maps Embed API:
<iframe
src="https://www.google.com/maps/embed?pb=
!1m3
!3m2
!1m1
!1s0xd62377123a70817%3A0x85e89b65fcf7c648"
width="400" height="400" frameborder="0" style="border:0" allowfullscreen>
</iframe>
m create Block with this syntax:
1 Digital - ID or place in current block?
2 Digital - value = size of new block
!<ID>m<value>
!1m3
!3m2
!1m1
!1s0xd62377123a70817%3A0x85e89b65fcf7c648
{}
{,,{}}
{,,{{}}}
{,,{{1s}}}
!1:{}
!1:{!3:{}}
!1:{!3:{!1:{}}}
!1:{!3:{!1:{1s}}}
I hope this helps!
Akubik's answer brought me on track. The parameter I describe is, despite its coordinate-like param1:param2-look, an identifier.
I was not able to find out what param1 is, but when a place (e. g., a store) is selected, param2 is the Google Maps customer id (CID) in hexadecimal encoding. In my given example, that is not the case. But, using another real-world example, the parameter:
!1s0x6ad63fbf56e24c27:0xe665b3308d32f379
can be understood like this
0xe665b3308d32f379 ---hex-to-dec---> 16601872622479930233
and https://google.com/maps?cid=16601872622479930233 will lead to the marked place.
How to extract the coordinates from that? If you only have a few samples, you can do it by hand. Click on the link above, and after 1-2 seconds, Google Maps will refresh the URL in the browser. It now contains the exact coordinates of the place (yes, this time the exact coordinates, not center of the viewport) in the !3d and !4d parameter.
If you have many samples and/or want to automatize the process, you have to use the Google Maps API (check for example this link).
What is missing: How to understand the parameter, if not a place, but an address was selected? For an example, see the link in my original question.
I know this is an old thread but, I managed to get something similar done.
This thread helped substantially to reduce my time wasted on that :)
which is to generate an embed URI. Check the link out
https://medium.com/#supun1001/how-to-generate-google-embed-links-programmatically-for-iframes-for-routes-only-d6dc225e59e8
Logic is implemented in the following simple web page
https://gpx2googlemaps.com/#/

Create link google maps from place content json list

I used googlemaps API to get places content:
{
"geometry" : {
"location" : {
"lat" : 21.007178,
"lng" : 105.854556
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "3c82fb7ade3d148ede6360226e0043397e4ce135",
"name" : "18, 51",
"place_id" : "ChIJNytjYvWrNTERfKb-r2Bqdv4",
"reference" : "CnRpAAAAI5c1ZenSc5l8H0Z71O4McKgBI9UjwVcP410JS7Fsc7LGTPx5UtphSud62OLNgADhIYVeXrkCbDPGf3_9aZUxbGyrvqB-JrcuPFVgtFd-lZfMt2fMEmVq6lYBVZfdj2gbW7WwqXsOkVRlsJjgjaQg6hIQQ_fR8a31Skpt8akDUt5CmxoUtNs983MCedA0LZCfivETQ0lpqCI",
"scope" : "GOOGLE",
"types" : [ "bus_station", "transit_station", "establishment" ],
"vicinity" : "40 Võ Thị Sáu, Thanh Nhàn"
}
How can I create place link to navigate to google maps by web browser from above infomation.
Looks like you are using the Google Places API webservice to get the JSON data. Now if you want to display the data on Maps you have to pass each JSON object (Place or location) in a marker and then initialize that inside a Google Map object.
Instead of doing all this hard work you can directly use the Google Maps Places Library for Javascript API V3 inside your app project. This would automatically enable your application to search for places (defined in this API as establishments, geographic locations, or prominent points of interest) contained within a defined area, such as the bounds of a map, or around a fixed point.
You can find all the information of how to implement it and display it inside the browser by clicking this link.
Hope this would Help!!

Google places api not working properly

I'm not getting search results while using the Google api for places. There are also no ratings coming like a week ago. Im getting results for far off places and not nearby. Has Google changing the api or should I wait a little more for Google to give a good places api.
Thanks
I experienced the same issue. Google changed the Places API in late June 2014 to deprecate the reference and id fields in favor of a single place_id. They also changed the detail level in the JSON response. For instance, not including the name parameter in your call like this...
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&key=YOURKEY
...returns results that look like this:
"html_attributions" : [],
"next_page_token" : "CoQC8gAAALD7H9pFpjSrFHDEn0_rzBef77uvO3hAvsO9u344Jh05RIsiVtkMvAbgZaYbp15lus4mOIbrWtbk-SIJ9j2B5ankZiTt9ZvJBUwOhjkBsCopBR_EhQQO4ZZciVQGFYVl-Zu4Y7vHSx6mKFzZ5rNeqVdFbBOfTeptNIjjs3re9EEkmqa_gFZ60J7DTw0Qgig_Vekq9I0aMF62Y3a3ZvAb4ElFpapxkvkHRRW_r6fYLR7L77JHzxheL_BVuNqDhM8F_lZl9gwe9g5vehb_xkwSOnIl001Ybdntipuyf_dmCpBg_58Vv0Xm0Z8MvNqLSeaE6B5vZXspYxZWqtHCN5andLUSEMgSnJKHtPzxTDkmZcmgulIaFFSiA6dQUakJXIEQCkulMheOBV2t",
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.871194,
"lng" : 151.19891
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "6237ce126ba1afabd5985b059d3d1eca6e9ee0da",
"name" : "Blue Fish",
"place_id" : "ChIJBaqDDzquEmsRcCI5e-3rStM",
"reference" : "CnRsAAAAibazLaEzCLq4fMIASFHDGG81Ls_hY5ycFP-GRfZP5dKRuLblqe8qrzf5BOKVZOtbRwNQ2PN34sQv5o0H_kL_LEZhKPFmpMz7qkAj6a262KGICKoxTznqRILF2bVZVk7SED0qRnpiyo_A304g30itnhIQBmp1tv7ZoYnOGnrqhtTXzhoU2HDzURqpVMfmpAYoEqbVDJg8J9s",
"scope" : "GOOGLE",
"types" : [ "restaurant", "food", "establishment" ],
"vicinity" : "Harbourside Shopping Centre/287 Darling Drive, Sydney CBD"
}
Whereas if you include the name parameter, like this...
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=YOURKEY
...your results return a more detailed response:
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.870775,
"lng" : 151.199025
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/travel_agent-71.png",
"id" : "21a0b251c9b8392186142c798263e289fe45b4aa",
"name" : "Rhythmboat Cruises",
"opening_hours" : {
"open_now" : false
},
"photos" : [
{
"height" : 270,
"html_attributions" : [],
"photo_reference" : "CnRnAAAAOCqDF9u4_e5cEPJq0J3M-37u9fa4IfMJK7-SceKf98mkZAnSbVLPUN-PoHBeW8_32daeNBA-H9dI3xuIERAyBAXfmXB0MbO26ITj0ryvJgHe6V6m2GhxJXFVpv_XSMBp8XsghrHXhfWFidj8p4WCtBIQetaqvTH1oI28Nsd-iHXqFxoU8m00lJGS1J6FJMfQl-kqZjXbf8s",
"width" : 519
}
]
As you can see, the more detailed response provides rating, opening hours, photos, etc., but also requires use of a more detailed URL string.
My app used to pull one set of restaurant data, then pass the information anywhere I needed it (from a TableViewController to a DetailView for example). With this new change, the only band-aid solution we can devise is to make two separate calls to the API. One to retrieve the basic upper layer of information from the JSON object for my TableViewController, the second (after tapping on the cell to create the new URL string, including the name parameter) to fetch the additional more detailed information like rating and opening hours. As you can imagine, this solution will increase the number of API calls tenfold as your users would essentially make an API call every time they reviewed the details of a place. No bueno.
As a result, we're researching other place indexes, such as the built-in Apple MKLocalSearch, which returns a similar, but not identical set of information as Google Places API. Maybe MKLocalSearch will suit your needs.
If others have found a better solution to this change, I think we'd all be open to it.
EDIT
It looks like they want us to use the place_id returned by the text search or nearby search to make another call to get place details. See here.

Google maps directions api json result decimal format for latitude and longitude differs on refresh

I am using the Google Maps Directions API v3 to get routes and show them on a mobile app. The code works fine, but suddently I found that sometimes fails. I ended up seeing that the same api call returns different LAT and LON values on refresh or recall.
For instance, the results of this query:
http://maps.googleapis.com/maps/api/directions/json?origin=41.158212,1.104743&destination=41.081765,1.131603&region=es&sensor=false
Sometimes gives me the coordinate values as
"end_address" : "Carrer de Barcelona, 61-63, 43840 Salou, Tarragona, España",
"end_location" : {
"lat" : 41.08180,
"lng" : 1.131470
},
and on refresh sometimes gives me this:
"end_address" : "Carrer de Barcelona, 61-63, 43840 Salou, Tarragona, España",
"end_location" : {
"lat" : 4108.179590000001,
"lng" : 113.147030
},
My errors come from getting the values as 4108 instead of 41.08. I can workaround this in my code but would like to know if anyone can help me out to find the root cause and try to ensure I always get the proper json answer.
Thanks!