使用地点ID或来自placeservice

时间:2015-12-01 14:23:15

标签: google-maps google-places-api

我使用googles placeservice在某些地方附近寻找不同的东西......比如超市,公共交通等......

我想打开一个新窗口,直接在maps.google上显示该地点。

我可以使用lat / lng:

执行此操作

https://www.google.dk/maps/@56.045495,10.085505,14z?hl=da

它获得了正确的地理位置,但我想让它显示具体位置,如果使用地图上的搜索找到的话:

https://www.google.dk/maps/place/Fakta/@56.045495,10.0833163,17z/data=!3m1!4b1!4m2!3m1!1s0x464c6993abe3de79:0xc036fb2b139e55de?hl=da

我或多或少地识别坐标,但无法重新创建数据部分

那么 - 如何从placeservice数据创建直接链接?

示例数据:

 {
         "geometry" : {
            "location" : {
               "lat" : 56.04549499999999,
               "lng" : 10.085505
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
         "id" : "f4c0b42302c72de733cd130f6589b2142de4f1e7",
         "name" : "Fakta",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 250,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/109513446981677175720\"\u003eFakta\u003c/a\u003e"
               ],
               "raw_reference" : {
                  "fife_url" : "https://lh3.googleusercontent.com/-zqiScJc18CQ/VTab-hXG8XI/AAAAAAAAAAQ/hwgNgYHwxMI/k/"
               },
               "width" : 250
            }
         ],
         "place_id" : "ChIJed7jq5NpTEYR3lWeEyv7NsA",
         "reference" : "CmRZAAAAAzaJO9Ozk3HNrAoVShZdMa2112V_2lh9Pj4p-_EmjqrDdeUtb81vOQGQ29A2LIlRTfyOriRssdKDKA39T9AKfIgQpg196jnKwP0kEX_O3pnZKroB6iAthowx9xz8FmSLEhDGbQEtuJZadYXCYvw3euRoGhT9i_8nJqSdku-WX3GimtT2c69syw",
         "scope" : "GOOGLE",
         "types" : [
            "grocery_or_supermarket",
            "food",
            "store",
            "point_of_interest",
            "establishment"
         ],
         "vicinity" : "Solbjerg Hedevej 25, Solbjerg"
      } 

1 个答案:

答案 0 :(得分:4)

使用place_id

制作Place Details Request
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJed7jq5NpTEYR3lWeEyv7NsA&key=YOUR_KEY_HERE

回复包含url字段:

   "result" : {
      // ... snip ...
      "url" : "https://maps.google.com/?cid=13850533866455848414",

该网址会将您直接带到Google地图上的地点:https://maps.google.com/?cid=13850533866455848414