Google Places API returning strange results - google-maps

I am using google places API to return basic information about businesses such as
- name
- address
- phone
and maybe images later but even the above 3 would be great initially.
The results being returned don't seem to be as accurate as when I search in google maps. For example, if I search for 'florist Athlone' in the town Athlone in Ireland I get 4 results, all are clearly florists.
However, if I use google places API and use Athlone as the coordinates like this with florist as the keyword
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=53.4232693,-7.9490146&radius=8000&name=nail%20salon&key=x
It returns weird results such as a shopping centre, a marketing company, a photographer etc. Now it does correctly return the 4 florists but is there a way via places or another API that can return more accurate results.
Obviously, if someone is looking for a florist and they see a marketing company and a photographer, the information looks reliable. What I like about places is that it gives 150,000 searches a day free. Ideally, the suggested API or method would also have a decent free plan.
This is just one example but there are tons of examples for all types of business categories where the info being returns is not accurate. I also thought about using the type value but that doesn't seem great. For example, you cant pass b&b you have to pass lodging which is too broad and I need to return specific categories like pub, restaurant, b&b, butcher etc
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 53.4242032,
"lng" : -7.934448300000001
},
"viewport" : {
"northeast" : {
"lat" : 53.42555302989273,
"lng" : -7.933098470107277
},
"southwest" : {
"lat" : 53.42285337010728,
"lng" : -7.935798129892721
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "4e0ff98af928a212bcd64e35c25278c7a962b1e0",
"name" : "A Room in Bloom",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 2368,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/113110406294245292993/photos\"\u003eGary Kearney\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAm5vmwNVndTiIiDiX-fGVhB-8aTx7Kyp4qMucuvcc80DMhGpn6nG0Q3DBK9_5jqT7fZDIctw-KHJ89RE_D2sJj5xr4Sy6zAYlVnyJx7VbRMqpHKY3Mr_eKmFTvnDKhP4CEhChU8nLg8ikqfsCcXukqoKGGhRVNPN5GdlO-KNWYgg3W3sLp-GiWg",
"width" : 4208
}
],
"place_id" : "ChIJQ-Uh0wVJXEgRHwfLO-9Qe_0",
"plus_code" : {
"compound_code" : "C3F8+M6 Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC3F8+M6"
},
"rating" : 4.6,
"reference" : "CmRbAAAAVbtKUhG5syxA1oSfs3xvlsZtRfM9CijH13Hml4lPi3xdNwN-Pvs3KJRQ5wd0ZBdFI1G5d3VaaZm0lQVqulKIBqc2DLul2X2eeDaTVQFV84X0WX9xkflqORHVsdoabZCrEhDeR78yzfbmWMpF6Mtml2QkGhRTtjvPgqdoaQNCklJy416Gb2094Q",
"scope" : "GOOGLE",
"types" : [ "florist", "store", "point_of_interest", "establishment" ],
"vicinity" : "Fairview Terrace, Garden Vale, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4230177,
"lng" : -7.949603499999998
},
"viewport" : {
"northeast" : {
"lat" : 53.42436752989271,
"lng" : -7.948253670107275
},
"southwest" : {
"lat" : 53.42166787010727,
"lng" : -7.950953329892719
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "d0a8341c1a26a933c926b94227f7e185954337c8",
"name" : "Dooley's Westend Flowers",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 3024,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/110208982636998757346/photos\"\u003eDooley's Westend Flowers\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAQEyT0e3Fi2X7GdSDWaS4NaQoPhq1WGr9KVJoqFnuRSEbGr07sEToiAtP0Jqo2IsOdpBTGY99kLThSO88D0ySco5zbVYG40vxIA-TOlgMP4nXAJKvgJPNzsRE6u05gbyeEhAKodedRy7xMHLiJ3BGu0pjGhQ7veW7qSB13wxp84JzJNhc2Y_2Jg",
"width" : 4032
}
],
"place_id" : "ChIJ5RDhM_xIXEgRUfEQvO3MJEw",
"plus_code" : {
"compound_code" : "C3F2+65 Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC3F2+65"
},
"rating" : 4.8,
"reference" : "CmRbAAAAeJhLEAtKzEaZ3BsoVcYdcD0mK35nmagxtMRDTkEXitI2eR_fS90rsUr65sp13YlLugzeLkC-fJQrvJfbZ9FzO0DhyjyQiifsI_SdttCNflNQoumRh0-JENcgXqWFd_wUEhDPqZJvkyl4d3HRHpa5UzNLGhQ081hZgVh0M36W2PutZOnYlsJ6Hw",
"scope" : "GOOGLE",
"types" : [
"florist",
"grocery_or_supermarket",
"home_goods_store",
"store",
"food",
"point_of_interest",
"establishment"
],
"vicinity" : "Magazine road, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4202395,
"lng" : -7.933982299999999
},
"viewport" : {
"northeast" : {
"lat" : 53.42158932989273,
"lng" : -7.932632470107277
},
"southwest" : {
"lat" : 53.41888967010728,
"lng" : -7.935332129892721
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "335dbc850f70f158aa2023c2f9d894bad2f069eb",
"name" : "Dooley's",
"opening_hours" : {},
"photos" : [
{
"height" : 4032,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111352362883151837153/photos\"\u003eMichael Carty\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAor8kyir_1aeJsWXo92PDIl4gNUpql3bGKUeXlH2zo8Uq8QfkOPQS0jwQ_nhuz4UzP1crIPY0wKtajgSQPxlgugNNJW9UOKrAS8-mxghnsfnVE__sDl9ZWWLj8MhRDRKzEhDaCNN-80IOdpWEgWk6hdrAGhQ0_CrCoKsLXQTSFcc1nt5ADx0ifQ",
"width" : 3024
}
],
"place_id" : "ChIJY-Qc2QRJXEgREay8iXABhMM",
"plus_code" : {
"compound_code" : "C3C8+3C Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC3C8+3C"
},
"rating" : 4.6,
"reference" : "CmRbAAAAtHL-8kOfiQcsIBrN81TotZ7IcnEw72N38f7q68cz-W55e5Z-VhIF5R7ZLG9dLy3XZkzIqOZC7w4k-w4UbB5YDIP89qmR_Ety4uMjf0D8ueF_pPsLPib9S_JipDt-kS-gEhAPFiIBWm0mitDS0rdQngO_GhQfb2qa7KMqK6Y76wW8og01gjbrFA",
"scope" : "GOOGLE",
"types" : [ "florist", "store", "point_of_interest", "establishment" ],
"vicinity" : "Golden Island (Kilmaine), Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4232928,
"lng" : -7.9396458
},
"viewport" : {
"northeast" : {
"lat" : 53.42463542989272,
"lng" : -7.938276270107278
},
"southwest" : {
"lat" : 53.42193577010728,
"lng" : -7.940975929892722
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "66ba2e9350b7d1cd1183c3a278e9946d1e21d0fe",
"name" : "Be Floral",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 1440,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/109574484271593171379/photos\"\u003eA Google User\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAEdHCug6ZcEp839GOoVYKUbWZqeW75DRzStWllllUzRHxmUtBObCmf6kajw6b-nK2aDlSamdKVFAAnWFyU7i4GoATn1JbVz0zRWGI0rmbZdyKQHKbxneo32tT_Pl3HsfPEhAeWIUO2lh-FaI8_Bxr2YwQGhQxy9LgWUd8ckYg3eV-IJJ-uEndPg",
"width" : 1920
}
],
"place_id" : "ChIJ0SZ17ANJXEgR-5UdcJuIpM4",
"plus_code" : {
"compound_code" : "C3F6+84 Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC3F6+84"
},
"rating" : 0,
"reference" : "CmRbAAAAujL-64C9k6SPSYVmc8RlqQXJBxPvviqqvzgb40ZJAz8kX4wWuqB_HWUO5D6VyTbSfMaUCa02hjVnRNzr9ISM_CdjkmIrNp2akwv7NznYDgF1o9xTGCMluuTT1MtpmFg3EhBS7eM287v1nw-30wu5IN-sGhTqZfI5f-qny12YPXJuvioHSwD-6g",
"scope" : "GOOGLE",
"types" : [ "florist", "store", "point_of_interest", "establishment" ],
"vicinity" : "Lloyd's Ln, Loughanaskin, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.43007069999999,
"lng" : -7.8923063
},
"viewport" : {
"northeast" : {
"lat" : 53.43142052989272,
"lng" : -7.890956470107278
},
"southwest" : {
"lat" : 53.42872087010728,
"lng" : -7.893656129892721
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "559974f9849741660baafdbd433c5cb934f2f411",
"name" : "Floral Cloud",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 609,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/105597253291213300228/photos\"\u003eA Google User\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAe-lw4ZpD_fbD5MTBOoKUOpYCYNTboDxFuu1r_j6elTPIu1_QMrZqzqBYzGf8iirE_feDjzeT6XRRWhTjNbaIBja500_FhA3zTAmibm0HFIoBHDhIGMRdWGfsMsypANB8EhC96QUKzxF5ez38wBflj0gZGhQrXVbi4WDiXebfOmjGVJ4EwFd4bA",
"width" : 1084
}
],
"place_id" : "ChIJMdt-IoFIXEgRmdwzL8HC50Y",
"plus_code" : {
"compound_code" : "C4J5+23 Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC4J5+23"
},
"rating" : 4.3,
"reference" : "CmRbAAAAkRrSGSx0ignasWUpJgWiSPgqqTpbr6ATUy3t-61nqH7FCvpnYmn1784H_CCfCzrSt_1uMrNwPHXRbmjFtbUuG5HAeWA7Db1Pu9G2SK9nvJTWbY6FzvOnjHU0sT2AexqmEhBAIgDxoWfQa9Sw9Pw-GIQVGhRY4qzIaUnfCPRW5HFwu3HEOmsqYA",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"vicinity" : "Unit 50, Blyry Industrial Estate, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.406841,
"lng" : -7.938007
},
"viewport" : {
"northeast" : {
"lat" : 53.40819082989272,
"lng" : -7.936657170107278
},
"southwest" : {
"lat" : 53.40549117010728,
"lng" : -7.939356829892722
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "ba1b851568d90d433d8fc18a0ddda3446b7d962a",
"name" : "Patricias Wedding Treasures",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 480,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/117902390620131484671/photos\"\u003ePatricias Wedding Treasures\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAkEmZoNaP4hqXcTH-3qKlyHNh5KQ3b05D3hASuqJ_oCOjnF0sBoBEGiM_AW111Kd60iwAX3GZMFTbvIB4Fhlg3OcIAlQiZWCBNuSpyUyhi1588s2MJgby7z5amSaGHf3hEhDq2CP7jIbbN6DQjnvHAC8mGhS_U7aX-r_BNy9V0iXMWfv5Wiez1A",
"width" : 640
}
],
"place_id" : "ChIJu5v_RyBJXEgRGM1aYEvmD0w",
"plus_code" : {
"compound_code" : "C346+PQ Golden Island, County Westmeath, Ireland",
"global_code" : "9C5JC346+PQ"
},
"rating" : 0,
"reference" : "CmRbAAAAd1bct3aUQYrpSsnHs-DOedUAPYl9FuUO4P9blXwvSt21rhkm8-IoJkrFUtjRaSdD0S8UW9tnTEvienOZAJ86Wq8Ypeb5ylubHrmdBlmP8oFNHe6SDITXJ6JDcMp2L_UQEhDoSKhOwIsY1VI0VIVtv5NuGhSP45FmfICFqvJpZCPQ0bfSolwgEA",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"vicinity" : "Golden Island, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4239152,
"lng" : -7.989224200000001
},
"viewport" : {
"northeast" : {
"lat" : 53.42556182989272,
"lng" : -7.988307570107279
},
"southwest" : {
"lat" : 53.42286217010728,
"lng" : -7.991007229892722
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "abe41b107c9ab2fd16763225006b0072cf06f393",
"name" : "Liam Kidney Photography",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 1536,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/100645956983550164138/photos\"\u003eLiam Kidney\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAA0ZHwKonfbiEuX-zDNs2_U9704br-fmS9gqazgzajJ6j9_kzFTrY_qgVZlHF9UyaLKq-KvmRcaPpUAY0ILOljInTdTeQC_aZ7MHWEnNHEXoeHIT3EGAODZm9rREBRaMMLEhBziDTx76q3EzTrDKtyx-cTGhThlbSNYNPIDz5IBkW900I0n6RAdg",
"width" : 2048
}
],
"place_id" : "ChIJL-WIf4hIXEgRTNE0T8MZBHQ",
"plus_code" : {
"compound_code" : "C2F6+H8 Monksland, County Roscommon, Ireland",
"global_code" : "9C5JC2F6+H8"
},
"rating" : 5,
"reference" : "CmRbAAAAinNcXzE02soMQisE8PC-LLmbXYXBh74SfpSEw4ODJghp8EGcA7E7zXoVxNG3xvLaRYCWk8h9qcQBqnqP6Oxzo3n0VcmbS5C0DJZs43NxFgLApnCPl8A85Gz7eynzaRWhEhDZfmuxwQCF4GfmiSz3j3GfGhQ8Za_ZMlHa1wmSHRPVtoIUEheg8w",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"vicinity" : "50 Ross Árd, Monksland, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4763658,
"lng" : -7.898927199999999
},
"viewport" : {
"northeast" : {
"lat" : 53.47771562989273,
"lng" : -7.897577370107276
},
"southwest" : {
"lat" : 53.47501597010729,
"lng" : -7.900277029892719
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
"id" : "202c490aa76d1fe877bae7b2a9b62e27ae2d187b",
"name" : "Glasson Hotel & Golf Club",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 2322,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/113442176282980152058/photos\"\u003emarcus 187\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAUEX6VhfjaGdoaCbY1iI0sPx3ja2hU5CAB6JJB5DJ1idsc4Mdw3kJFnS2Mtqx61Ty9neRMR0Red0uyFu-gamqP_IHDsW_IaOenM1DT-vOqL8kpwakU0dvDm8WaCOn8eSOEhAqWy96iezK2c2opTlx2e_DGhSUD5-FiYnBkobMOOlN9trbk5Cogw",
"width" : 4128
}
],
"place_id" : "ChIJrVOmAudJXEgRIqez0LFZyHI",
"plus_code" : {
"compound_code" : "F4G2+GC Killinure South, County Westmeath, Ireland",
"global_code" : "9C5JF4G2+GC"
},
"rating" : 4.5,
"reference" : "CmRbAAAA26_DiJ5XJ-sty-_bpm0A9X-UW6ftcB07mXCixo6e9Gqgqq4FslRqWzcBNJAWbmmhug_c1MorfCiQF52kJXNOxc-6X_fM2E-q853tp4F5OjzuxicBBK3AoOWcj73RwS2XEhBS2cSBMLVD84D4CPMaBtseGhQPEgR2oR-prQkK98Aj0nL1R1xSrg",
"scope" : "GOOGLE",
"types" : [
"bar",
"lodging",
"restaurant",
"food",
"point_of_interest",
"establishment"
],
"vicinity" : "Killinure Cottage, Killinure, Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.430479,
"lng" : -7.893891
},
"viewport" : {
"northeast" : {
"lat" : 53.43182882989272,
"lng" : -7.892541170107278
},
"southwest" : {
"lat" : 53.42912917010727,
"lng" : -7.895240829892722
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "b9a92eaa8780cc6b38232d20d0da5617c70e0304",
"name" : "FCDM - Full Circle Digital Marketing",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 607,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/112102288553428624320/photos\"\u003eFCDM\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAlL1f48FXqYsCZgyqjCajqxFR5jq-48nv5AakzESAYlqk-kbeR1Zg4QayQtt74KUS6e_UTWdnD0DDFmTYDrtPZVqmj2Tjl4rABDJh1X9AOMF8A1QlrpqcR5Nky_7BQ-55EhCnXVkSGDC-dZP1rmp9iiFYGhQ0a1AbzgrnREnUOBcVsFh7XSebPg",
"width" : 1080
}
],
"place_id" : "ChIJo0nTMY9IXEgRElwEQnqwbmI",
"plus_code" : {
"compound_code" : "C4J4+5C Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC4J4+5C"
},
"rating" : 3.7,
"reference" : "CmRbAAAAkUitIdEDXa-ieKhT6AtJyTNUHWu4-x950qE5sPwujFW5-m65iSaYmx_QORopdZtyzIIZtxrmBeDHN3FA0LAXQxi3Blh5wpq1fkQDw4135pm9cYyIC4RIYMz2utgjvx1hEhC7PxyDVuZQw6GqjT3zZDgsGhS2sC-UlbjDCtkr4OVQQoRv1trv9Q",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"vicinity" : "Unit 50, Blyry Business and Commercial Park., Athlone"
},
{
"geometry" : {
"location" : {
"lat" : 53.4204895,
"lng" : -7.9342238
},
"viewport" : {
"northeast" : {
"lat" : 53.42183932989272,
"lng" : -7.932873970107278
},
"southwest" : {
"lat" : 53.41913967010728,
"lng" : -7.935573629892722
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "624d46cc4c06746da8bc9bd616f1844b63ab269b",
"name" : "Golden Island Shopping Centre",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 2268,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/109922865072642849852/photos\"\u003eBongani Mashengele\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAAO7ai7tjnPI3wUyM_0tsVR7FlnxXrglecFW9hAKDFwjvmIBSxk9c2NvaAEQjCXl4WRU-h09jwm1-kq1dSIgYudW8tr_d9wxvUtIOTq1oz5BW6zv7HMZS8UeIVYV6dEwsEhBoJBgWrCHQW-OMaWDdUipbGhT11E8yQvzX8Tu-_AIEVXVJrhYHoQ",
"width" : 4032
}
],
"place_id" : "ChIJbeXe5wRJXEgRcysPAxpgOX8",
"plus_code" : {
"compound_code" : "C3C8+58 Athlone, County Westmeath, Ireland",
"global_code" : "9C5JC3C8+58"
},
"rating" : 4.3,
"reference" : "CmRbAAAA4PYRNntFEbQ5Bbg9Bzzp9lncwKQOEccTsZ8zLqmdlh5mK0j-7wUCZNjmomBvXcAG_EVvR6wEeaAFkRvs704nZvoBYfbYa2NqAzsF_S2maj-ZyNGrSdaMWsqoXNF3a1vUEhALSMQDnpJUHuIxvQh5U_2PGhRQA_QuMGa5WorYG9eeh0KBpuQfhg",
"scope" : "GOOGLE",
"types" : [ "shopping_mall", "point_of_interest", "establishment" ],
"vicinity" : "Golden Island, Golden Island (Kilmaine), Athlone"
}
],
"status" : "OK"
}

Use
input=nail%20salon
In the url you provided replacing
name=nail%20salon

Have you tried using the Google's API nearbySearch(...) function? That function allows you to specify three parameters: Location (latitude, longitude coordinates), radius (around Location) & type (the type is the keyword here, because based on this Google's API will determine the search results).
var SearchPlaces = {
GPMHotels: ['hotel']
, GPMCoffeeShop: ['cafe']
, GPMFoodPlaces: ['restaurant']
, GPMShoppingPlaces: ['shopping_mall']
};
var service = new google.maps.places.PlacesService(GPMap);
function SearchGPMapServiceNearPlacesFn(service) {
function GetHTML(place) {
var distance = "";
if (place.geometry && place.geometry.location) {
var fromLatLng = new google.maps.LatLng(GPMapLocation.lat, GPMapLocation.lng);
distance = google.maps.geometry.spherical.computeDistanceBetween(fromLatLng, place.geometry.location);
distance = Math.ceil(distance).toLocaleString('#languaje');
}
var html = "* " + (distance ? distance + " m. " : "") + place.name + ". "
+ place.formatted_address + ". " +
(place.international_phone_number || "");
return html;
}
function GetPlaceDetails(place_id) {
if (!place_id) return;
service.getDetails({
placeId: place_id
}, function (place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
//-->> console.log({ fn: 'GetPlaceDetails', item: place });
$("#GPMNearSitesList").append($('<li>').html(GetHTML(place)));
}
});
}
service.nearbySearch({
location: GPMapLocation,
radius: GPMapOptions.searchRadiusList,
},
function (results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
GetPlaceDetails(results[i].place_id);
//-->>console.log({ fn: "SearchGPMapServiceNearPlacesFn", item: results[i] });
}
}
});
}
See: https://developers.google.com/places/web-service/search

Looking at https://developers.google.com/places/web-service/search it seems that name is not a valid parameter. I suspect it is being ignored. Try using input instead:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=53.4232693,-7.9490146&radius=8000&input=nail%20salon&key=x

Related

discrepancies between google places api nearby search and results returned on Maps

if I point google Maps to a location [-20.1419057374276,-157.33203817679]
and then carry out a nearby search for "tour operator" I get, in the case of that location, 9 results https://www.google.com/maps/search/Tour+operator/#-21.2333094,-159.7948598,14z
if I use Google Places API (in this case in R using httr:GET - I have tried googleway also) I do not get any results returned (status:"ZERO_RESULTS"):
res.wild<-GET(paste("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=",paste(centers$lat[i],centers$lon[i],sep=","),"&radius=35000&keyword=tour+operator&key=",myKey,sep=""))
where centers$lat[i],centers$lon[i] is -20.1419057374276,-157.33203817679
I used to use the radar search which is no longer available but seemed to return results consistent with a direct search on google maps. Going through the documentation, I cannot see from where this discrepancy come.
Anyone has any idea?
thanks!
The coordinates shown in the URL of Google Maps are not reliable as they take zoom into account. If you want to get exact coordinates, use other methods such as Geocoding.
The -20.1419057374276,-157.33203817679 coordinate points to Mauke, Cook Islands: https://developers.google.com/maps/documentation/utils/geocoder/#q%3D-20.141906%252C-157.332038
If you want to get nearby places from Rarotonga, Cook Islands, then you can e.g. use -21.229237,-159.776349 instead: https://developers.google.com/maps/documentation/utils/geocoder/#q%3D-21.229237%252C-159.776349
Try this request using the above coordinates:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-21.229237,-159.776349&radius=35000&keyword=tour+operator&key=YOUR_KEY
The output is close to what you get in Google Maps:
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -21.2573049,
"lng" : -159.7311111
},
"viewport" : {
"northeast" : {
"lat" : -21.25565152010728,
"lng" : -159.7299870701073
},
"southwest" : {
"lat" : -21.25835117989272,
"lng" : -159.7326867298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "d54699b006411b5a5f9450ee2b30e88ad7deec44",
"name" : "Captain Tamas Lagoon Cruizes",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 645,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/102745446521532412613\"\u003eCaptain Tamas Lagoon Cruises\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAA6O-c8lb1bdh75I9dWRqjmTZanPhSx8LgNlVxR9ZMtoLkQMQ0uzSMGFr_xtfwdID9wPS2DlNIXO4aqHc_eVGzjDjPNzLyO_f8YvIp6gaP3xoYGRfKoOb_aZpKOqS2INnMEhA75QSRQC4FQnM8sXketTROGhRC1SgaNX6Hg1S6PIxlVQEOiVM4CQ",
"width" : 859
}
],
"place_id" : "ChIJmSbDLojTV3EROL5C9_iW6kg",
"plus_code" : {
"compound_code" : "P7V9+3H Ngatangiia District, Cook Islands",
"global_code" : "53C2P7V9+3H"
},
"rating" : 4.8,
"reference" : "ChIJmSbDLojTV3EROL5C9_iW6kg",
"scope" : "GOOGLE",
"types" : [ "travel_agency", "point_of_interest", "establishment" ],
"user_ratings_total" : 102,
"vicinity" : "Muri Beach, Muri"
},
{
"geometry" : {
"location" : {
"lat" : -21.258145,
"lng" : -159.732045
},
"viewport" : {
"northeast" : {
"lat" : -21.25663512010728,
"lng" : -159.7310816201073
},
"southwest" : {
"lat" : -21.25933477989272,
"lng" : -159.7337812798927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "354b255213a808490880fe1b9551d0f442aae382",
"name" : "Koka Lagoon Cruises",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 3024,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/103124684904518750526\"\u003eHuong Tran\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAbNLjafLjIMjmUaJ-jilVZuJfWt79C_IoPEC-epFVSSSSlwQLo9_RMVRWl_dAAx4naup6P8aCr-F-TtTtzWpB_cI0-B1RbBcbp4mIvGxqLQvBeX6DWKi-gaT1UjsfKhG4EhDDBz4JWPKmCx4Mq3hiUv1iGhTKRpHYORs6lj-VYV-bqwTo6VFw0g",
"width" : 4032
}
],
"place_id" : "ChIJu4ZfKXbUV3ERrKo9dhOCJiI",
"plus_code" : {
"compound_code" : "P7R9+P5 Ngatangiia District, Cook Islands",
"global_code" : "53C2P7R9+P5"
},
"rating" : 4.9,
"reference" : "ChIJu4ZfKXbUV3ERrKo9dhOCJiI",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"user_ratings_total" : 67,
"vicinity" : "Muri Beach, Rarotonga"
},
{
"geometry" : {
"location" : {
"lat" : -21.2204492,
"lng" : -159.8285893
},
"viewport" : {
"northeast" : {
"lat" : -21.21907502010728,
"lng" : -159.8273637201073
},
"southwest" : {
"lat" : -21.22177467989272,
"lng" : -159.8300633798927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "6ca2b13851e47e4474fd197888d503d352de2f15",
"name" : "Tik-e Tours",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 4032,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/117619328803821181982\"\u003eA Google User\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAdq12AeQCjoIpk09GCOx-laja1_iJ2Vzgnonu1quJ0bIzdOjV6YOvBHYoJT8hXwlyaUGB5C5o14HS3i-FUdwOuln7OFsY56r-bguBuQGV5_ukiyNHrCiCeRU5M7PhaLo2EhAfer7M013sz3i2uVsxTEfSGhQqWr9yhhB8UKcNGps3kOxCFcQa3A",
"width" : 3024
}
],
"place_id" : "ChIJGe7bPVnQV3ERHI7vgH-Ou3c",
"plus_code" : {
"compound_code" : "Q5HC+RH Arorangi District, Cook Islands",
"global_code" : "53C2Q5HC+RH"
},
"rating" : 4.9,
"reference" : "ChIJGe7bPVnQV3ERHI7vgH-Ou3c",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"user_ratings_total" : 10,
"vicinity" : "Arorangi District"
},
{
"geometry" : {
"location" : {
"lat" : -21.2655311,
"lng" : -159.7819558
},
"viewport" : {
"northeast" : {
"lat" : -21.26411742010728,
"lng" : -159.7805932701072
},
"southwest" : {
"lat" : -21.26681707989272,
"lng" : -159.7832929298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "91cdd05c5d95d60981a890fd54886ebcad4b8ba9",
"name" : "Snorkel Cook Islands",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 2304,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/112866284698762632354\"\u003eFe'ena Syme Buchanan\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAd8e9zm-Wsa8hR-YkjI-bbLB_N_qJ9k5TOaYAjiyYhrHUJjQkdC9DmFc3RZVnQKpcS-QY7A3AtJPIG5OLH8dNSAwiQUB2tYmB-CMD6ZDRUSqqBpa3P_p2y9jc2sv9Lqd4EhDJooK75NFPEz0k_YsX38WMGhS1znNvtNWs-xwCg1OL0sF1JRHRZQ",
"width" : 3456
}
],
"place_id" : "ChIJKTe2bjLXV3ERHUapU18Vydg",
"plus_code" : {
"compound_code" : "P6M9+Q6 Takitumu District, Cook Islands",
"global_code" : "53C2P6M9+Q6"
},
"rating" : 5,
"reference" : "ChIJKTe2bjLXV3ERHUapU18Vydg",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"user_ratings_total" : 1,
"vicinity" : "Rarotonga"
},
{
"geometry" : {
"location" : {
"lat" : -21.2031499,
"lng" : -159.7862431
},
"viewport" : {
"northeast" : {
"lat" : -21.20180492010728,
"lng" : -159.7848997701073
},
"southwest" : {
"lat" : -21.20450457989272,
"lng" : -159.7875994298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "6c6524b3437e98c139998b5ec06ea81fd3ff2f5f",
"name" : "Black Watch Charters",
"place_id" : "ChIJP8sjaZbRV3ERaB06jfdehkY",
"plus_code" : {
"compound_code" : "Q6W7+PG Avarua District, Cook Islands",
"global_code" : "53C2Q6W7+PG"
},
"rating" : 0,
"reference" : "ChIJP8sjaZbRV3ERaB06jfdehkY",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "establishment" ],
"user_ratings_total" : 0,
"vicinity" : "Avarua District"
},
{
"geometry" : {
"location" : {
"lat" : -21.1994895,
"lng" : -159.8003902
},
"viewport" : {
"northeast" : {
"lat" : -21.19841532010728,
"lng" : -159.7989554201073
},
"southwest" : {
"lat" : -21.20111497989272,
"lng" : -159.8016550798928
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "5f02f471fe2868a51943041aa684874f8269ef7b",
"name" : "Raro Safari Tours & Concierge Desk",
"photos" : [
{
"height" : 3024,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/100947574557964297982\"\u003eJAY PILISI\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAA34pKKofPm9XF97_CcfSLVGq3y2AHn-linLaeEc1RfHRjpbJThl5EQuxKKmamNZ1i4cvqSu1-65He6nLolErQJLXEFDMPis4-5dKmK2TXS2-jyEsnrkcKKPiYqZD3B3jcEhC_GBl65rela41ctpewfxc3GhSt4oGQNCPui4k4j6vFU4o3hQWDDw",
"width" : 4032
}
],
"place_id" : "ChIJgRilfy3RV3ERpi1MKCgisSw",
"plus_code" : {
"compound_code" : "R52X+6R Avarua District, Cook Islands",
"global_code" : "53C2R52X+6R"
},
"rating" : 4.9,
"reference" : "ChIJgRilfy3RV3ERpi1MKCgisSw",
"scope" : "GOOGLE",
"types" : [
"tourist_attraction",
"travel_agency",
"point_of_interest",
"establishment"
],
"user_ratings_total" : 10,
"vicinity" : "Avarua District"
},
{
"geometry" : {
"location" : {
"lat" : -21.249997,
"lng" : -159.822227
},
"viewport" : {
"northeast" : {
"lat" : -21.24868352010728,
"lng" : -159.8209628201073
},
"southwest" : {
"lat" : -21.25138317989272,
"lng" : -159.8236624798928
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "affb3957b65c2ca105d0c5e63e547e22b6d73493",
"name" : "Adventure Cook Islands Ltd",
"opening_hours" : {
"open_now" : false
},
"photos" : [
{
"height" : 1063,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111619238938552241021\"\u003eAdventure Cook Islands Ltd\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAQ4B12jlUrWlqwK1gWdfEEoGndrBWhviA8DTSI-Q-UoGmyR_7b7mkbtI361dC9dAZh3-Z0YlOYTdvVze9Vuw9qjFNecFMcPGO30ISi6DXCPezDEM_eTZj_mPbCDdLh8cyEhBlTzcXyYr7Atj69fRyPkVhGhQI_eSnR2CEQfCZNOXfM9UOC7uytA",
"width" : 1417
}
],
"place_id" : "ChIJOw686NzQV3ERYaRq_jbcJjw",
"plus_code" : {
"compound_code" : "Q52H+24 Arorangi District, Cook Islands",
"global_code" : "53C2Q52H+24"
},
"rating" : 4.9,
"reference" : "ChIJOw686NzQV3ERYaRq_jbcJjw",
"scope" : "GOOGLE",
"types" : [ "travel_agency", "point_of_interest", "establishment" ],
"user_ratings_total" : 21,
"vicinity" : "Kavera Beach, Arorangi Rarotonga"
},
{
"geometry" : {
"location" : {
"lat" : -21.220265,
"lng" : -159.828848
},
"viewport" : {
"northeast" : {
"lat" : -21.21891637010728,
"lng" : -159.8274922201073
},
"southwest" : {
"lat" : -21.22161602989272,
"lng" : -159.8301918798927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "aca36479a072b313810c37ac835e50440bf3b81f",
"name" : "Dive Rarotonga",
"opening_hours" : {
"open_now" : false
},
"photos" : [
{
"height" : 337,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/102784390999532361399\"\u003eDive Rarotonga\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAW5A88HqZDDXA6her_GXw7zoxj2wB_U1O-tUubEBFNCteiAoPscB0o5-N5KvN-oY9TIaMnTD1-UhU1wNiX7-nSVMiUTIUcZIzEZFsDgJrO-xPL0hbm5jE887kq3V1VYVIEhCpMlOYcEqSDWLEDAPcnodCGhSBnJ1dO8GpFHZEnTMP6l9t2zpZpA",
"width" : 600
}
],
"place_id" : "ChIJkSU-1V3QV3ER3yczeMV8I_k",
"plus_code" : {
"compound_code" : "Q5HC+VF Arorangi District, Cook Islands",
"global_code" : "53C2Q5HC+VF"
},
"rating" : 4.9,
"reference" : "ChIJkSU-1V3QV3ER3yczeMV8I_k",
"scope" : "GOOGLE",
"types" : [ "travel_agency", "point_of_interest", "store", "establishment" ],
"user_ratings_total" : 33,
"vicinity" : "Yellow A-Frame, Main Road, Arorangi District"
},
{
"geometry" : {
"location" : {
"lat" : -21.252595,
"lng" : -159.730144
},
"viewport" : {
"northeast" : {
"lat" : -21.25122567010727,
"lng" : -159.7289091701073
},
"southwest" : {
"lat" : -21.25392532989272,
"lng" : -159.7316088298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "f0b212e097fc057cb51138594070cfe5c014d436",
"name" : "Pacific Divers",
"opening_hours" : {
"open_now" : false
},
"place_id" : "ChIJRUYyzojTV3ER9iL5iSVfHNo",
"plus_code" : {
"compound_code" : "P7W9+XW Ngatangiia District, Cook Islands",
"global_code" : "53C2P7W9+XW"
},
"rating" : 0,
"reference" : "ChIJRUYyzojTV3ER9iL5iSVfHNo",
"scope" : "GOOGLE",
"types" : [ "travel_agency", "school", "point_of_interest", "establishment" ],
"user_ratings_total" : 0,
"vicinity" : "Ara Tapu, Muri"
},
{
"geometry" : {
"location" : {
"lat" : -21.2012422,
"lng" : -159.8060292
},
"viewport" : {
"northeast" : {
"lat" : -21.19968582010728,
"lng" : -159.8046350701073
},
"southwest" : {
"lat" : -21.20238547989272,
"lng" : -159.8073347298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "e53fbdf110553cb3a56e69dedfc348e1da4e0172",
"name" : "Turama Pacific Travel Group",
"photos" : [
{
"height" : 525,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/104663734301544398423\"\u003eA Google User\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAvgs-ezM5FNldJ1bfCf_sV0Ql58Nj54UKuirPef1T0FNqc6U2YLdpREuexg20VBWNwRdet--vuGenVsazreVEio-ezp4VEzYbrMv2BVbILKGswlL83NN8hT0BPEK3gTOaEhADvZmluOWXh0kRYgtcRE3oGhQ95v3wdXzFgfh06tOico2RmMJWiA",
"width" : 700
}
],
"place_id" : "ChIJuUvKeLbRV3EROJNkUZhNG5g",
"plus_code" : {
"compound_code" : "Q5XV+GH Avarua District, Cook Islands",
"global_code" : "53C2Q5XV+GH"
},
"rating" : 5,
"reference" : "ChIJuUvKeLbRV3EROJNkUZhNG5g",
"scope" : "GOOGLE",
"types" : [ "travel_agency", "point_of_interest", "establishment" ],
"user_ratings_total" : 1,
"vicinity" : "Avarua District"
}
],
"status" : "OK"
}
Hope this helps!

Google Directions API transit returns always "ZERO_RESULTS"

i'm developing an app that use google API to obtain a transport solution to reach a location at a desired time.
My code that call google API work perfectly with "driving" and "walking" travel mode, but with "transit" and "bicycling" the response is always marked with the status "ZERO_RESULTS" and no routes is calculated.
This, by the google documentation, means that transit and bicycling are not available in the country where the solution must be calculated.
I tried with several country and I always had the same result, I tried also with the Google example (for transit) in the overview and it doesn't work.
The parameters that I pass with the HTTPS request are: origin, destination, travel mode, arrival_time.
The first thing that I tried is to change arrival_time, in case the value is referred to the past or to a too distant future, but it doesn't work.
In case I don't pass "arrival_time" the response is perfect, but I don't understand because in the Google Documentation is clear that arrival_time is a possible argument of the https request also with the transit travel mode. Without this argument the request is useless for my goal.
The curious thing is that if i pass "transit" (with arrival or departure time) the response is this:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
And if I pass "bicycling" (with all the other parameters unchanged):
{
"available_travel_modes" : [ "DRIVING", "WALKING", "TRANSIT" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
So in the second case the API said that TRANSIT is available and this doesn't make sense at all!
The format of the location that I use is geographical coordinates to avoid cases of ambiguity.
Hope that I give enough information to make you able to help me.
EDIT: sorry, i was thinking that my post was clear enough.
I use Google Directions API: https://developers.google.com/maps/documentation/directions/
My problem is with "transit" and "bicycling" as travel mode and is not a code problem, but the problem appears at the level of https response, even with the google example for "transit" that can be found on the overview i obtain a "ZERO_RESULTS" response.
This is the URL of the example:
https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&mode=transit&arrival_time=1391374800&key=YOUR_API_KEY
And here is the two URL that get me the two response that I copied above:
with transit:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
and with bicycling:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
in the code I use for origin and destination geographical coordinates as here:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=transit&arrival_time=1513162800000&key=++API_KEY++
the only difference is that google do not recognize geocoded waypoints:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [ {}, {} ],
"routes" : [],
"status" : "ZERO_RESULTS"
}
If I use "driving" as travel mode this worked:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=driving&arrival_time=1513162800000&key=++API_KEY++
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJC5u9LazGhkcRXAZQFNDTpKc",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4731019,
"lng" : 12.6177051
},
"southwest" : {
"lat" : 41.9028523,
"lng" : 9.1839517
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "573 km",
"value" : 572600
},
"duration" : {
"text" : "5 ore 51 min",
"value" : 21069
},
"end_address" : "Via Silvio Pellico, 2, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"steps" : [
{
"distance" : {
"text" : "93 m",
"value" : 93
},
"duration" : {
"text" : "1 min",
"value" : 19
},
"end_location" : {
"lat" : 41.9035781,
"lng" : 12.4959908
},
"html_instructions" : "Procedi in direzione \u003cb\u003enord\u003c/b\u003e da \u003cb\u003ePiazza della Repubblica\u003c/b\u003e verso \u003cb\u003eVia Giuseppe Romita\u003c/b\u003e",
"polyline" : {
"points" : "ycw~F}ugkAU?I#E#E#a#RG#EDED_#d#OP"
},
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"travel_mode" : "DRIVING"
},
// cut
{
"distance" : {
"text" : "52 m",
"value" : 52
},
"duration" : {
"text" : "1 min",
"value" : 14
},
"end_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"html_instructions" : "Continua su \u003cb\u003eVia Santa Margherita\u003c/b\u003e",
"polyline" : {
"points" : "ogotGoxaw#`#`#j#h#"
},
"start_location" : {
"lat" : 45.4669622,
"lng" : 9.189359399999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 192
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"html_instructions" : "Svolta a \u003cb\u003esinistra\u003c/b\u003e e prendi \u003cb\u003eVia Silvio Pellico\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "aeotGcvaw#Xw#DCBAxC#~A?d#A"
},
"start_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "A1/E35 e A1",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
and if I use "transit" without an arrival time it works:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.
189981999999986&mode=transit&key=++API_KEY++
and:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJRYxePKzGhkcRsgPwamn2Pfo",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4969308,
"lng" : 12.5528041
},
"southwest" : {
"lat" : 41.892252,
"lng" : 9.188611
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169733
},
"departure_time" : {
"text" : "10:10",
"time_zone" : "Europe/Rome",
"value" : 1513156231
},
"distance" : {
"text" : "571 km",
"value" : 571467
},
"duration" : {
"text" : "3 ore 45 min",
"value" : 13502
},
"end_address" : "Piazza del Duomo, 1, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "0,1 km",
"value" : 102
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Cammina fino a Repubblica",
"polyline" : {
"points" : "wcw~F_vgkA#CBADABA#A#?B?D?B?B#B?B#BBB##BBBDH#D#H##?D?BDRBL?#DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "54 m",
"value" : 54
},
"duration" : {
"text" : "1 min",
"value" : 49
},
"end_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"html_instructions" : "Procedi in direzione \u003cb\u003esudest\u003c/b\u003e verso \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "wcw~F_vgkA#CBADABA#A#?B?D?B?B#B?B#BBB##BBBDH#D#H##?D?B"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "48 m",
"value" : 48
},
"duration" : {
"text" : "1 min",
"value" : 38
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Esci dalla rotonda e prendi \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "oaw~FstgkADRBL?#DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"travel_mode" : "WALKING"
}
],
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,4 km",
"value" : 437
},
"duration" : {
"text" : "1 min",
"value" : 46
},
"end_location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"html_instructions" : "Metropolitana verso Anagnina",
"polyline" : {
"points" : "u_w~FwqgkAeBIBoA#I|ByM~CmELR"
},
"start_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"name" : "Termini"
},
"arrival_time" : {
"text" : "10:12",
"time_zone" : "Europe/Rome",
"value" : 1513156353
},
"departure_stop" : {
"location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"name" : "Repubblica"
},
"departure_time" : {
"text" : "10:11",
"time_zone" : "Europe/Rome",
"value" : 1513156307
},
"headsign" : "Anagnina",
"line" : {
"agencies" : [
{
"name" : "Atac",
"phone" : "011 39 06 57003",
"url" : "http://www.atac.roma.it/"
}
],
"color" : "#e27439",
"name" : "Metro A",
"short_name" : "MEA",
"url" : "http://muovi.roma.it/percorso/js?query=MEA&cl=1",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 1
},
"travel_mode" : "TRANSIT"
},
{
"distance" : {
"text" : "2,6 km",
"value" : 2641
},
"duration" : {
"text" : "6 min",
"value" : 330
},
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"html_instructions" : "Metropolitana verso San Donato",
"polyline" : {
"points" : "//collapsed//"
},
"start_location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"name" : "Duomo"
},
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169730
},
"departure_stop" : {
"location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"name" : "Centrale FS"
},
"departure_time" : {
"text" : "13:50",
"time_zone" : "Europe/Rome",
"value" : 1513169400
},
"headsign" : "San Donato",
"line" : {
"agencies" : [
{
"name" : "COMUNE DI MILANO",
"phone" : "011 39 02 0202",
"url" : "http://www.muoversi.milano.it/"
}
],
"color" : "#ffea00",
"name" : "M3 - Linea Gialla",
"short_name" : "3",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 4
},
"travel_mode" : "TRANSIT"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "",
"warnings" : [
"Le indicazioni per tragitti a piedi sono in versione beta. Presta attenzione – questo percorso potrebbe non disporre di marciapiede o aree pedonali."
],
"waypoint_order" : []
}
],
"status" : "OK"
}
The issue in your request is the value that you pass as an arrival_time parameter. Please note that this value must be in seconds:
arrival_time — Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. You can specify either departure_time or arrival_time, but not both. Note that arrival_time must be specified as an integer.
https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests
You are passing milliseconds 1513162800000 that corresponds to 03/22/49920 # 8:00am (UTC), the correct value is 1513162800 that corresponds to 12/13/2017 # 11:00am (UTC).
The request should be:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835%2C12.496365500000024&destination=45.4642035%2C9.189981999999986&mode=transit&arrival_time=1513162800&key=YOUR_API_KEY
The same request in Directions calculator:
https://directionsdebug.firebaseapp.com/?origin=41.9027835%2C12.496365500000024&destination=45.4642035%2C9.189981999999986&mode=transit&arrival_time=1513162800
I hope this helps!
In case it helps someone else, I also found that setting a departure_time too far in the future (more than a year in my case) led to a "ZERO_RESULTS" response. Making it closer to the present fixed this.

How to get parse json - SwiftyJSON

I'm using SwiftyJSON.
I have a json string like this:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJkcemZ9r9jT8RCoy7cipVk3Q",
"types" : [ "route" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJzYyVGtcFjj8RMoV0IaoNhzA",
"types" : [ "route" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 35.7884236,
"lng" : 51.43490389999999
},
"southwest" : {
"lat" : 35.7056256,
"lng" : 51.3073962
}
},
"copyrights" : "Map data ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "20.9 km",
"value" : 20893
},
"duration" : {
"text" : "32 mins",
"value" : 1936
},
"end_address" : "Tehran Province, Tehran, Hossein, Iran",
"end_location" : {
"lat" : 35.7883586,
"lng" : 51.43490389999999
},
"start_address" : "Tehran Province, Tehran, Kooy-e-Bimeh, Rostam, Iran",
"start_location" : {
"lat" : 35.7056307,
"lng" : 51.3167437
},
"steps" : [
{
"distance" : {
"text" : "59 m",
"value" : 59
},
"duration" : {
"text" : "1 min",
"value" : 21
},
"end_location" : {
"lat" : 35.70562779999999,
"lng" : 51.31739839999999
},
"html_instructions" : "Head \u003cb\u003eeast\u003c/b\u003e on \u003cb\u003eRostam\u003c/b\u003e toward \u003cb\u003e4th Bimeh St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Burgerich (on the right)\u003c/div\u003e",
"polyline" : {
"points" : "ew|xEsxexH?W?w#?s#"
},
"start_location" : {
"lat" : 35.7056307,
"lng" : 51.3167437
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.1 km",
"value" : 135
},
"duration" : {
"text" : "1 min",
"value" : 30
},
"end_location" : {
"lat" : 35.7868183,
"lng" : 51.4303372
},
"html_instructions" : "Continue onto \u003cb\u003eSharifi Manesh St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Embassy of Switzerland In Tehran (on the left)\u003c/div\u003e",
"polyline" : {
"points" : "cllyEyy{xHSIQSIIYWk#[_Ak#YQ"
},
"start_location" : {
"lat" : 35.7857769,
"lng" : 51.4295729
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 304
},
"duration" : {
"text" : "1 min",
"value" : 51
},
"end_location" : {
"lat" : 35.7852475,
"lng" : 51.4330904
},
"html_instructions" : "\u003cb\u003eSharifi Manesh St\u003c/b\u003e turns \u003cb\u003eright\u003c/b\u003e and becomes \u003cb\u003eElahiyeh St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by باشگاه الهیه (on the left)\u003c/div\u003e",
"polyline" : {
"points" : "srlyEs~{xHpBwEdA}BxAqCf#}#"
},
"start_location" : {
"lat" : 35.7868183,
"lng" : 51.4303372
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.4 km",
"value" : 359
},
"duration" : {
"text" : "1 min",
"value" : 70
},
"end_location" : {
"lat" : 35.7884241,
"lng" : 51.4337388
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eKhazar St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by MaryamHair (on the left)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "yhlyEyo|xHwBYwCg#wA[}AQuAM}AC"
},
"start_location" : {
"lat" : 35.7852475,
"lng" : 51.4330904
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.1 km",
"value" : 105
},
"duration" : {
"text" : "1 min",
"value" : 39
},
"end_location" : {
"lat" : 35.7883586,
"lng" : 51.43490389999999
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e at هنرستان مفتح onto \u003cb\u003eHossein\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "s|lyE{s|xH?AJeF"
},
"start_location" : {
"lat" : 35.7884241,
"lng" : 51.4337388
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "ew|xEsxexH?oA"
},
"summary" : "Hakim Expy",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
what I want to get is routes->legs->distance->text.
my codes:
let json = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
if let data = json.data(using: String.Encoding.utf8) {
let json = JSON(data: data)
print("--->\(json["routes"]["legs"]["distance"]["text"].string)")
}
print returns --->nil.
routes and legs are arrays, you have to get the first entry first:
let json = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
if let data = json.data(using: String.Encoding.utf8) {
let json = JSON(data: data)
if let route = json["routes"].first {
if let leg = route["legs"].first {
print("--->\(leg["distance"]["text"].string)")
}
}
}
p.s. You may need to do some logic checking if you don't want the first entry in the arrays.

Google Map JSON for low bandwidth networks

How to change google map JSON so that redundant stuff is not downloaded and speed up an app on low bandwidth networks. For example app doesn't support navigation hence steps are not required in JSON which is also downloaded and makes app slow on low bandwidth networks.
For Example:-
Google Map JSON between source and destination:-
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJbZ--gzESrjsRsmxa_tmvhlI",
"types" : [ "route" ]
},
{
"geocoder_status" : "OK",
"place_id" : "Elk4NjksIDEydGggTWFpbiBSb2FkLCBLb3JhbWFuZ2FsYSAzIEJsb2NrLCBLb3JhbWFuZ2FsYSwgQmVuZ2FsdXJ1LCBLYXJuYXRha2EgNTYwMDM0LCBJbmRpYQ",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 12.959155,
"lng" : 77.7091214
},
"southwest" : {
"lat" : 12.9206335,
"lng" : 77.6264824
}
},
"copyrights" : "Map data ©2015 Google",
"legs" : [
{
"distance" : {
"text" : "12.5 km",
"value" : 12510
},
"duration" : {
"text" : "29 mins",
"value" : 1750
},
"end_address" : "869, 12th Main Road, Koramangala 3 Block, Koramangala, Bengaluru, Karnataka 560034, India",
"end_location" : {
"lat" : 12.9280212,
"lng" : 77.6267905
},
"start_address" : "PFS Driveway, Lakshminarayana Pura, AECS Layout, Marathahalli, Bengaluru, Karnataka 560037, India",
"start_location" : {
"lat" : 12.959155,
"lng" : 77.70615509999999
},
"steps" : [
{
"distance" : {
"text" : "0.3 km",
"value" : 283
},
"duration" : {
"text" : "1 min",
"value" : 68
},
"end_location" : {
"lat" : 12.9569421,
"lng" : 77.70609429999999
},
"html_instructions" : "Head \u003cb\u003esouth\u003c/b\u003e on \u003cb\u003ePFS Driveway\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eRestricted usage road\u003c/div\u003e",
"polyline" : {
"points" : "wabnAo~gyMzK_AH?D#DD#F?F#N?D#J#D?F#D"
},
"start_location" : {
"lat" : 12.959155,
"lng" : 77.70615509999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "26 m",
"value" : 26
},
"duration" : {
"text" : "1 min",
"value" : 6
},
"end_location" : {
"lat" : 12.9567068,
"lng" : 77.70613229999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e to stay on \u003cb\u003ePFS Driveway\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eRestricted usage road\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "{sanAa~gyMl#G"
},
"start_location" : {
"lat" : 12.9569421,
"lng" : 77.70609429999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.1 km",
"value" : 138
},
"duration" : {
"text" : "1 min",
"value" : 59
},
"end_location" : {
"lat" : 12.9568247,
"lng" : 77.70486409999999
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eMarathalli Bridge Service Rd\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "mranAi~gyMC^Q|E"
},
"start_location" : {
"lat" : 12.9567068,
"lng" : 77.70613229999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "36 m",
"value" : 36
},
"duration" : {
"text" : "1 min",
"value" : 8
},
"end_location" : {
"lat" : 12.9565042,
"lng" : 77.70486959999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMunnekollal Main Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "csanAkvgyM~#A"
},
"start_location" : {
"lat" : 12.9568247,
"lng" : 77.70486409999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.5 km",
"value" : 482
},
"duration" : {
"text" : "1 min",
"value" : 83
},
"end_location" : {
"lat" : 12.9563276,
"lng" : 77.7091214
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMarathalli Bridge Service Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "cqanAmvgyMPkGFuCV_GHeB?K#CDWD]g#C"
},
"start_location" : {
"lat" : 12.9565042,
"lng" : 77.70486959999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.8 km",
"value" : 838
},
"duration" : {
"text" : "2 mins",
"value" : 142
},
"end_location" : {
"lat" : 12.956896,
"lng" : 77.70141439999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMarathalli Bridge/Old Airport Rd/Varthur Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinue to follow Old Airport Rd/Varthur Rd\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "apanA_qhyMs#nVE|A?#AB?#ErBInAG~BMlCA^ARC^CR?B?#?r#AXA`#"
},
"start_location" : {
"lat" : 12.9563276,
"lng" : 77.7091214
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.4 km",
"value" : 411
},
"duration" : {
"text" : "1 min",
"value" : 62
},
"end_location" : {
"lat" : 12.9533531,
"lng" : 77.7003715
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e toward \u003cb\u003eNH7\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "ssanAy`gyMRJHDFDvBb#xBf#ZHpK`B"
},
"start_location" : {
"lat" : 12.956896,
"lng" : 77.70141439999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "31 m",
"value" : 31
},
"duration" : {
"text" : "1 min",
"value" : 23
},
"end_location" : {
"lat" : 12.9531397,
"lng" : 77.7001892
},
"html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e toward \u003cb\u003eNH7\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "m}`nAizfyMHF^Z"
},
"start_location" : {
"lat" : 12.9533531,
"lng" : 77.7003715
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "3.8 km",
"value" : 3796
},
"duration" : {
"text" : "6 mins",
"value" : 373
},
"end_location" : {
"lat" : 12.9274228,
"lng" : 77.6798031
},
"html_instructions" : "Slight \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eNH7\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by VIMS Super Specialty Hospital (on the left in 550 m)\u003c/div\u003e",
"maneuver" : "turn-slight-left",
"polyline" : {
"points" : "c|`nAeyfyM`Ft#lBRzFl#|Fj#x#JzATn#J`AR~A`#fB`#dB`#j#Ph#PhKdCr#R^HVJZJ`#Nb#RdAh#bAf#x#`#r#X\\N`#PtAp#pBdA~#f#`Ah#lAx#`Av#n#n#xB|BfBpBb#f#fBtBtDdE`AdAbCpC`CjCtC`DpIlJxF|G^h#PTNXXf#\\r#Th#p#dBl#~AjA~CxA~Dx#zBVp#p#hBr#hBJR"
},
"start_location" : {
"lat" : 12.9531397,
"lng" : 77.7001892
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "3.0 km",
"value" : 3010
},
"duration" : {
"text" : "5 mins",
"value" : 270
},
"end_location" : {
"lat" : 12.9237183,
"lng" : 77.6540827
},
"html_instructions" : "Keep \u003cb\u003eleft\u003c/b\u003e to stay on \u003cb\u003eNH7\u003c/b\u003e",
"maneuver" : "keep-left",
"polyline" : {
"points" : "k{{mAwybyMRf#rBxFbD|I^~#\\~#~C`I^jAX|#Vv#zAnEfBlF|#~BvAbEtBfFZ|#hFbNT~##J?J#J#J?L?JAL?LAJAJCLALEREXe#hC_AnEMr#Kn#a#xC]bCa#zBk#lCaA|D_AfD_AvDc#fBYrAMx#OlAe#vD"
},
"start_location" : {
"lat" : 12.9274228,
"lng" : 77.6798031
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.4 km",
"value" : 438
},
"duration" : {
"text" : "1 min",
"value" : 66
},
"end_location" : {
"lat" : 12.924442,
"lng" : 77.6501267
},
"html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eAgra Exit\u003c/b\u003e toward \u003cb\u003eSarjapur Main Rd\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "gd{mA_y}xMQb#Mv#QtAu#rGYjCCXCXA\\AXAP?P?r#"
},
"start_location" : {
"lat" : 12.9237183,
"lng" : 77.6540827
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1.8 km",
"value" : 1816
},
"duration" : {
"text" : "5 mins",
"value" : 304
},
"end_location" : {
"lat" : 12.9248137,
"lng" : 77.63406830000001
},
"html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eSarjapur Main Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Karthikshekar Hospital (on the left in 1.3 km)\u003c/div\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "wh{mAi`}xMEDCDEFCFA#I`#I\\?#AV?R#|#?JD~#Dx#Bl#DtB#TDx#Dd#?NDz#?P#L?V?l#?nC#^#\\#P#H#DFTx#jD\\jBf#jC`#fCVjADVDP#H?H?JAH?FADADADCFCHmArEEL_BpFCHA#ADGJIRKPW`#[f#S^Wl#KXEJCJA#AHCFCHAHERCNANAPAD?F?F#PBVNtAPxB`#lELbA"
},
"start_location" : {
"lat" : 12.924442,
"lng" : 77.6501267
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "77 m",
"value" : 77
},
"duration" : {
"text" : "1 min",
"value" : 44
},
"end_location" : {
"lat" : 12.9250061,
"lng" : 77.6335821
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003e80 Feet Main Rd/Mahatyagi Laksmidevi Rd\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ak{mA}{yxMFfA#PSB]B"
},
"start_location" : {
"lat" : 12.9248137,
"lng" : 77.63406830000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.6 km",
"value" : 579
},
"duration" : {
"text" : "2 mins",
"value" : 101
},
"end_location" : {
"lat" : 12.9245984,
"lng" : 77.62833669999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003e1st Cross Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Sandeepani (on the right)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "il{mA{xyxMDb#VdCL~APzBz#hILzBCh#Gl#i#rB"
},
"start_location" : {
"lat" : 12.9250061,
"lng" : 77.6335821
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.2 km",
"value" : 174
},
"duration" : {
"text" : "1 min",
"value" : 37
},
"end_location" : {
"lat" : 12.9261219,
"lng" : 77.628711
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003e8th Main Rd\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "wi{mAcxxxM_Dk#uBYYC"
},
"start_location" : {
"lat" : 12.9245984,
"lng" : 77.62833669999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 264
},
"duration" : {
"text" : "1 min",
"value" : 58
},
"end_location" : {
"lat" : 12.9270734,
"lng" : 77.6264824
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003e3rd Cross Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "gs{mAmzxxMe#zAe#xA}#lCs#xB"
},
"start_location" : {
"lat" : 12.9261219,
"lng" : 77.628711
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.1 km",
"value" : 111
},
"duration" : {
"text" : "1 min",
"value" : 46
},
"end_location" : {
"lat" : 12.9280212,
"lng" : 77.6267905
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003e12th Main Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by the park (on the right)\u003c/div\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the right\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ey{mAolxxM}D}#"
},
"start_location" : {
"lat" : 12.9270734,
"lng" : 77.6264824
},
"travel_mode" : "DRIVING"
}
],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "wabnAo~gyMdL_AJFBd#BX#Dl#GU|F~#APkG^uKHqBF[D]g#Cy#lYAFErBInAUlGKfBArAA`#RJPJpFjAlLjBh#b#`Ft#lBRxNxAtC`#pB^fEbApCr#rLvCfCt#dAb#hCpAlD|AfEvB`CpAlAx#`Av#hDlDhLtM|MdOpIlJxF|Gp#~#h#`Ar#|AdGdPvD`K^z#vGvQ|#~B~C`I^jAp#tBbE|LtCbIpCdHhFbNT~##VBp#Er#QhAeBxIYbB_A|Ga#zBk#lCaA|D_AfDcB~Gg#lCu#dGQb#Mv#gAhJ]dDEv#CpBSZUbA?tBJxBHbDLdCFrB?|DB|#BZHZvAvGhArGd#~BAf#IXwD|MO\\iAnBk#lAQd#K^Ov#En#Dp#pA`NHxAq#F|#dKz#hILzBKvAi#rB_Dk#oC]}D|L}D}#"
},
"summary" : "NH7",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
Required JSON for some application:-
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJbZ--gzESrjsRsmxa_tmvhlI",
"types" : [ "route" ]
},
{
"geocoder_status" : "OK",
"place_id" : "Elk4NjksIDEydGggTWFpbiBSb2FkLCBLb3JhbWFuZ2FsYSAzIEJsb2NrLCBLb3JhbWFuZ2FsYSwgQmVuZ2FsdXJ1LCBLYXJuYXRha2EgNTYwMDM0LCBJbmRpYQ",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 12.959155,
"lng" : 77.7091214
},
"southwest" : {
"lat" : 12.9206335,
"lng" : 77.6264824
}
},
"copyrights" : "Map data ©2015 Google",
"legs" : [
{
"distance" : {
"text" : "12.5 km",
"value" : 12510
},
"duration" : {
"text" : "29 mins",
"value" : 1750
},
"end_address" : "869, 12th Main Road, Koramangala 3 Block, Koramangala, Bengaluru, Karnataka 560034, India",
"end_location" : {
"lat" : 12.9280212,
"lng" : 77.6267905
},
"start_address" : "PFS Driveway, Lakshminarayana Pura, AECS Layout, Marathahalli, Bengaluru, Karnataka 560037, India",
"start_location" : {
"lat" : 12.959155,
"lng" : 77.70615509999999
},
}
],
"overview_polyline" : {
"points" : "wabnAo~gyMdL_AJFBd#BX#Dl#GU|F~#APkG^uKHqBF[D]g#Cy#lYAFErBInAUlGKfBArAA`#RJPJpFjAlLjBh#b#`Ft#lBRxNxAtC`#pB^fEbApCr#rLvCfCt#dAb#hCpAlD|AfEvB`CpAlAx#`Av#hDlDhLtM|MdOpIlJxF|Gp#~#h#`Ar#|AdGdPvD`K^z#vGvQ|#~B~C`I^jAp#tBbE|LtCbIpCdHhFbNT~##VBp#Er#QhAeBxIYbB_A|Ga#zBk#lCaA|D_AfDcB~Gg#lCu#dGQb#Mv#gAhJ]dDEv#CpBSZUbA?tBJxBHbDLdCFrB?|DB|#BZHZvAvGhArGd#~BAf#IXwD|MO\\iAnBk#lAQd#K^Ov#En#Dp#pA`NHxAq#F|#dKz#hILzBKvAi#rB_Dk#oC]}D|L}D}#"
},
"summary" : "NH7",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
Omitting parts of the JSON response is not a functionality in the APIs.
If you wish to request this, please do so in the issue tracker:
https://code.google.com/p/gmaps-api-issues/issues/entry?template=Directions%20API%20-%20Feature%20Request
However, I wouldn't expect this to be ever part of the API. For one thing, it sounds like it'd be of limited use, and it can be implemented in your own server: proxy requests to the API, then trim responses.
Perhaps you could also use SPDY:
https://developers.google.com/speed/spdy/

How to display "Google API directions" polylines with leaflet?

I would like to display an itinerary on a map with leaflet.
For this, I make a get request on the Google maps directions API. I get a json like this:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 51.5103406,
"lng" : -0.0627423
},
"southwest" : {
"lat" : 51.5049264,
"lng" : -0.0898856
}
},
"copyrights" : "Données cartographiques ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "3,0 km",
"value" : 2959
},
"duration" : {
"text" : "7 minutes",
"value" : 427
},
"end_address" : "29 Fowey Close, Londres E1W 2JP, Royaume-Uni",
"end_location" : {
"lat" : 51.5064421,
"lng" : -0.0627423
},
"start_address" : "8 Southwark Street, Londres SE1 1TL, Royaume-Uni",
"start_location" : {
"lat" : 51.5049264,
"lng" : -0.0898856
},
"steps" : [
{
"distance" : {
"text" : "0,6 km",
"value" : 601
},
"duration" : {
"text" : "1 minute",
"value" : 77
},
"end_location" : {
"lat" : 51.5099409,
"lng" : -0.0870841
},
"html_instructions" : "Prendre la direction \u003cb\u003enord-est\u003c/b\u003e sur \u003cb\u003eBorough High St/A3\u003c/b\u003e vers \u003cb\u003eBedale St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre A3\u003c/div\u003e\u003cdiv style=\"font-size:0.9em\"\u003eEntrée dans une section à péage\u003c/div\u003e",
"polyline" : {
"points" : "ypjyHxpPCG_#o#QY_AkAE?C?CCQSEGEEMQEEACGGIGeAo#]OA?ECQGGC_#KgHeBqAc#a#Iq#WYG_AUi#OIACAYG"
},
"start_location" : {
"lat" : 51.5049264,
"lng" : -0.0898856
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 152
},
"duration" : {
"text" : "1 minute",
"value" : 25
},
"end_location" : {
"lat" : 51.50989,
"lng" : -0.0883307
},
"html_instructions" : "Prendre légèrement \u003cb\u003eà gauche\u003c/b\u003e sur \u003cb\u003eArthur St\u003c/b\u003e",
"maneuver" : "turn-slight-left",
"polyline" : {
"points" : "cpkyHf_PGB_#EK?A?I#GFEHAJAJ?Z?V#NBRBPDVBFDHDLDFFFFFJFXL"
},
"start_location" : {
"lat" : 51.5099409,
"lng" : -0.0870841
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,6 km",
"value" : 590
},
"duration" : {
"text" : "1 minute",
"value" : 72
},
"end_location" : {
"lat" : 51.50955829999999,
"lng" : -0.080139
},
"html_instructions" : "Prendre \u003cb\u003eà gauche\u003c/b\u003e sur \u003cb\u003eUpper Thames St/A3211\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre A3211\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "yokyH`gPZ}DFu#Dg#H}#Bk#P_CRsDJuAJiB\\qE#QF_ABiA?i#CUCc#Ce#CWCMAIG_#Ke#Oa#ACQi#Qm#"
},
"start_location" : {
"lat" : 51.50989,
"lng" : -0.0883307
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,5 km",
"value" : 498
},
"duration" : {
"text" : "1 minute",
"value" : 73
},
"end_location" : {
"lat" : 51.5093097,
"lng" : -0.0737046
},
"html_instructions" : "Continuer sur \u003cb\u003eByward St/A100\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre A100\u003c/div\u003e\u003cdiv style=\"font-size:0.9em\"\u003eSortie de section à péage dans 400 m, au niveau de Minories/A1211\u003c/div\u003e",
"polyline" : {
"points" : "wmkyHzsNG[CWCUAS?E?c#?I?M#u##I#_AFs#Jo#DYBM?G?C?C?K?QAs#A]AaACe#Ae#AQM{ASqAIc#CMa#{BEW?I?K?IBK#GHSHOHOJMHKLMRQVOPU"
},
"start_location" : {
"lat" : 51.50955829999999,
"lng" : -0.080139
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,5 km",
"value" : 472
},
"duration" : {
"text" : "1 minute",
"value" : 54
},
"end_location" : {
"lat" : 51.5090739,
"lng" : -0.06770899999999999
},
"html_instructions" : "Continuer sur \u003cb\u003eMinories/A1203\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre A1203\u003c/div\u003e",
"polyline" : {
"points" : "elkyHrkMXc#XYHAJORg#VgAT}#Ry#Nq#FWDOD]B]?W?WASAWM_B]gDEe#Gi#i#uCo#uC"
},
"start_location" : {
"lat" : 51.5093097,
"lng" : -0.0737046
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,3 km",
"value" : 297
},
"duration" : {
"text" : "1 minute",
"value" : 57
},
"end_location" : {
"lat" : 51.5065805,
"lng" : -0.0666981
},
"html_instructions" : "Prendre \u003cb\u003eà droite\u003c/b\u003e sur \u003cb\u003eVaughan Way\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ujkyHdfL`Ak#VQZYZ_#JSJOJMFGJGJG#ALCHCPC~#?n#AL?`#?p#?\\F"
},
"start_location" : {
"lat" : 51.5090739,
"lng" : -0.06770899999999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,3 km",
"value" : 272
},
"duration" : {
"text" : "1 minute",
"value" : 41
},
"end_location" : {
"lat" : 51.5068938,
"lng" : -0.0629257
},
"html_instructions" : "Prendre \u003cb\u003eà gauche\u003c/b\u003e sur \u003cb\u003eKennet St\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "c{jyHz_LASASAKCMM]Uo#ESGSAOAQ?SAwAFkB#c#FuCKcBAa#"
},
"start_location" : {
"lat" : 51.5065805,
"lng" : -0.0666981
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "77 m",
"value" : 77
},
"duration" : {
"text" : "1 minute",
"value" : 28
},
"end_location" : {
"lat" : 51.5064421,
"lng" : -0.0627423
},
"html_instructions" : "Prendre \u003cb\u003eà droite\u003c/b\u003e sur \u003cb\u003eFowey Close\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eVotre destination se trouvera sur la droite\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "a}jyHhhKrAANABA#C#G?ECEMG"
},
"start_location" : {
"lat" : 51.5068938,
"lng" : -0.0629257
},
"travel_mode" : "DRIVING"
}
],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "ypjyHxpPc#w#qAeBI?UW_#e#IKoAw#w#[g#OgHeBqAc#sAa#yA]qA[GB_#EM?QHGT?nAFd#H^Xf#RNXLZ}DL}ALiB|#sN^cFJiCC_AGiAQoAo#uBYiAGm#AgADmC\\kC?[EeDEkAOmBcA_GEa#?UDSRc#T]VYj#a#j#y#XYHAJORg#l#eCb#kBLg#H{#?o#Ck#k#gGMoAi#uCo#uCxA}#v#y#Vc#RUVOj#M~CAp#?\\FCg#EYc#mAMg#Ca#AkBHoCFuCKcBAa#rAARCBKCKMG"
},
"summary" : "A3",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
};
I see there's some fields polyline with some weird data in it but I don't know what it represents. How can I display these?
That's a Google maps encoded polyline.
You can use this library to decode them at the appropriate resolution:
Polyline decoder (and encoder)
Basically they are an ascii encoded binary structure containing a set of polylines for multiple zoom levels.
You can actually use the Leaflet plugin: Leaflet.encoded . That'll put the Google Encoded Polyline on the Leaflet map.
The polyline data is encoded. I had this same issue creating a rubygem to do more or less the same thing. I came across a script written by a guy named George Lantz that decodes the string into points. I have it included as ruby in my gem here. You can probably figure out the logic in whatever language you prefer.
Ruby Script to Decode GMaps Polyline Data