Reputation: 3973
I am working on Android application in which I want to get the coordinates of the search place. Right now I am only getting the names and description of the place but not the coordinates that it Latitude and Longitude. My URL and response is given below.
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=karachi&sensor=true&key=MY_KEY
{
"predictions" : [
{
"description" : "Karachi Darbar - 10th Street - Oud Metha - Dubai - United Arab Emirates",
"id" : "66487f019fefe55e2fdd889a5902661dd8bce4eb",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJW_YoydNCXz4RwTx4gOxOrTg",
"reference" : "CmRVAAAAZ2JaZnVCxKFxn3qtlI0adppFvEJoe-D3NUQWNN0AIfUl0yhKFVm6F_yt2VUGW3x4j5DN6y5jxgkpgVNGCMgE7gxnZ2D1oHpZMEyeuaPgQBmrhP4OrsK0K5ZqLJJPNUOVEhBUBctSVLyD65tVUo0H3jeFGhSln3l44jAdvrmAQi6kSEOEdfHhPg",
"terms" : [
{
"offset" : 0,
"value" : "Karachi Darbar"
},
{
"offset" : 17,
"value" : "10th Street"
},
{
"offset" : 31,
"value" : "Oud Metha"
},
{
"offset" : 43,
"value" : "Dubai"
},
{
"offset" : 51,
"value" : "United Arab Emirates"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Karachi Darbar - 33 B Street - Al Karama - Dubai - United Arab Emirates",
"id" : "bb3e1227cce8b23d3ff172a3285db2defd742de7",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJB4u8R9dCXz4RUeKUXKVjgOE",
"reference" : "CmRWAAAAfVwdVthVlSfEK10__jrSkqQpBCmc_JILX3Ya7eA09oiweiGwCoq8MoqVzQ9BTOnN7MWfD5RTL83jlWcTvypFEEsMliHpBhsytKTiCAXMn90ffjcS037VRziEBKW53WbsEhCoOZZ7H2jv_GtaP52wA2FhGhQsw8ltBOqHCxEK1gTefMfQ4qzzbA",
"terms" : [
{
"offset" : 0,
"value" : "Karachi Darbar"
},
{
"offset" : 17,
"value" : "33 B Street"
},
{
"offset" : 31,
"value" : "Al Karama"
},
{
"offset" : 43,
"value" : "Dubai"
},
{
"offset" : 51,
"value" : "United Arab Emirates"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Karachi Darbar - Al Karama - Dubai - United Arab Emirates",
"id" : "7ab1b31e281218ec69777aede6d28b3bf5a70f90",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJb3yfr95CXz4RU4qzVfNY5Bs",
"reference" : "ClRHAAAAlB1PCqHp8_JAMSmpWa29T9XiQ3Wa9qh6ttuC1wh9L3axfEAngculrdf989Z0WrohwyUcytxkPLIH9CZzddphWz26R1b8NkJuCKuQKTqKEb0SEMvw3t6N-ZMX5MCeW9Gh10QaFKSoBa8LaQTjcIocrwlvHumQEIoT",
"terms" : [
{
"offset" : 0,
"value" : "Karachi Darbar"
},
{
"offset" : 17,
"value" : "Al Karama"
},
{
"offset" : 29,
"value" : "Dubai"
},
{
"offset" : 37,
"value" : "United Arab Emirates"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Karachi, Sindh, Pakistan",
"id" : "e65bd2b56cea82ce2b33391e9deee4951396ece7",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJv0sdZQY-sz4RIwxaVUQv-Zw",
"reference" : "CjQwAAAAqul1rii1VJ6L-fd1hiMQbpvPLHyAwaomCTG_6l_7PPkz1jwqWqkl51bavj1CGLdKEhAk6GFORGWurnJAqE2xzm29GhQoVDUqp11bs7O_B8DOLpTumCAgzw",
"terms" : [
{
"offset" : 0,
"value" : "Karachi"
},
{
"offset" : 9,
"value" : "Sindh"
},
{
"offset" : 16,
"value" : "Pakistan"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Karachi Darbar Restaurant - Al Mateena Street - Deira - Dubai - United Arab Emirates",
"id" : "7b28747c93dc316b477e11e75bede5da26d7bdab",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"place_id" : "ChIJLbxiB7dcXz4RUy9ny3FXR9Y",
"reference" : "CnRjAAAAs97khr1wHc1GeYxYTt2pRhv9NJPpNtekSGXLz22C6SJfo-6MKapTrnbAg1F_GzwDOuj87kiQe4inXDhFdBqcdH1a7BColMli3wRmuR76ib3AV4ouLuqqHYrZ0IrVeRsNDtjEHfPWyiKsLFrgB9jcIxIQ3z3-VFwCHUHHYa1_PvH6SxoUa7crfBXrD-Ma7Sr2pJGjoagJpeU",
"terms" : [
{
"offset" : 0,
"value" : "Karachi Darbar Restaurant"
},
{
"offset" : 28,
"value" : "Al Mateena Street"
},
{
"offset" : 48,
"value" : "Deira"
},
{
"offset" : 56,
"value" : "Dubai"
},
{
"offset" : 64,
"value" : "United Arab Emirates"
}
],
"types" : [ "establishment" ]
}
],
"status" : "OK"
}
Upvotes: 0
Views: 1016
Reputation: 6821
The best way is that you have to use the geocode api of google like as
http://maps.google.com/maps/api/geocode/json?address=karachi&sensor=false
If the limited access then no need any google api key.
In response, there is a json object "location" inside "geometry" where lat and lng present which will give you a co-ordinate of your entered location (karachi)
geometry: { bounds: { northeast: { lat: 25.2703106, lng: 67.46845189999999 }, southwest: { lat: 24.7519801, lng: 66.6609568 } }, location: { lat: 24.8614622, lng: 67.0099388 }, location_type: "APPROXIMATE", viewport: { northeast: { lat: 25.2703106, lng: 67.46845189999999 }, southwest: { lat: 24.7519801, lng: 66.6609568 } } }
Upvotes: 1