Android地图搜索地点

时间:2015-03-17 19:16:27

标签: android google-maps

我正在开发Android应用程序,我想在其中获取搜索位置的坐标。现在我只得到地方的名称和描述,但不是纬度和经度的坐标。我的网址和回复如下。

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"
}

2 个答案:

答案 0 :(得分:2)

您需要使用Place ID标记来获取Lat / Long

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJb3yfr95CXz4RU4qzVfNY5Bs&key=AddYourOwnKeyHere

答案 1 :(得分:1)

最好的方法是你必须使用google的geocode api,如

http://maps.google.com/maps/api/geocode/json?address=karachi&sensor=false

  

如果访问受限,则无需任何google api密钥。

作为回应,“几何”内有一个json对象“location”,其中 lat和lng存在,它会给你一个<您输入的位置(卡拉奇)的强>坐标

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
    }
  }
}