在没有地图的背景下使用Google Places服务

Use Google Places service in the background without a map

本文关键字:Google Places 服务 背景 地图      更新时间:2023-09-26

我正在开发一款在后台运行并跟踪用户位置的Ionic应用程序。

我想做的一件事是使用谷歌的位置服务来检查距离用户所在地50米半径内是否有地下车站。如果有的话,我想通知后端进行一些额外的处理。

问题是Places服务的初始化需要您传递一个地图或一个将显示结果的节点。但由于该应用程序是在后台运行的,我不想显示任何检索到的数据,所以我没有这些数据。

是否有其他初始化服务的方法?如果没有,你知道我还可以使用其他服务吗?

您正在寻找的是Google Places API Web服务。

以下是来自网站的示例电话:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670,151.1957&radius=500&types=food&name=cruise&key=YOUR_API_KEY

它返回:

{
   "debug_log" : {
      "line" : []
   },
   "html_attributions" : [],
   "logging_info" : {
      "experiment_id" : [],
      "query_geographic_location" : "AU"
   },
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : -33.86879,
               "lng" : 151.194217
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "21a0b251c9b8392186142c798263e289fe45b4aa",
         "name" : "Rhythmboat Cruises",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 426,
               "html_attributions" : [
                  "'u003ca href='"https://www.google.com/maps/views/profile/104066891898402903288'"'u003eRhythmboat Cruises'u003c/a'u003e"
               ],
               "photo_reference" : "CmRdAAAA-YL_I_Gk02blOX6S0nKHry8PFu9pDyp3Y9AnqISsa3Eq8mkbdD5mXuu1Fax60s0nSy3iiX-h5j-ztyLHcc1-782MsLQsgLLa4t3ZgDmCMll-a8ABapZGnZwDKByk67LFEhBgedv_u_eYFsEo9ay8jxJjGhTUHKPJ4G82vBJqSNliuv7UlAtclw",
               "width" : 640
            }
         ],
         "place_id" : "ChIJyWEHuEmuEmsRm9hTkapTCrk",
         "reference" : "CnRmAAAAvQlMKw-XtxEY4vWFCvudF7CEMQGI5ycNbfVgGl9rAF75fdiPOiLJw1k9NL2v8ZIJsOJuRS3Lm9Dw1vga4ajycAs7PlxN1MVnnYT9la0pBvEvSQNlyvszKANS1R4P7Mvk_jhqswMggqCUtwJ13LN2hRIQOiAkLTWUi3DOjVVOw7J5IRoUb_cJyJaJNqKdmkDM2f0OjQjh9F0",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Pyrmont Bay Wharf (Near Australia Maritime Museum), Pyrmont, NSW 2009"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.867591,
               "lng" : 151.201196
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "a97f9fb468bcd26b68a23072a55af82d4b325e0d",
         "name" : "Australian Cruise Group",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 1331,
               "html_attributions" : [
                  "'u003ca href='"https://www.google.com/maps/views/profile/110751364053842618118'"'u003eAustralian Cruise Group'u003c/a'u003e"
               ],
               "photo_reference" : "CmRdAAAAtEoj29FJcNBccrsu6bHt0xgwVGhYlciCY1fe6gTr_d5_KkeP3LITnOwnpNRJWnX39B04-aIBOKXKJH6ltx948T5vWIYBoah1yZDXsWngWZ5kMsK7xyCB5P_q_xBIBxxUEhAYWeB4PiOm_Jy093fB-j0iGhSYmIs9xB2aa6u-RH8V8lZEk-Q5ig",
               "width" : 2000
            }
         ],
         "place_id" : "ChIJrTLr-GyuEmsRBfy61i59si0",
         "reference" : "CnRqAAAAFbukrZvRNsc05TreHUCrPEya5NcN9v0fFLLaK-D1fSyxFTuQlUDhDstU3qwXKw_fADX4W6guUkexax1nufgiYIuGCKoZPEnup1r-LhGGNz9dn1uf9Of5iOtZ1XgCeDjJaYvGbSB3C0pAXL8r9kOsmhIQbx2Sia2DAWTjtSZwuh5aehoUhM6upqBCDLhGruZAGGsCOwAiIq8",
         "scope" : "GOOGLE",
         "types" : [
            "restaurant",
            "travel_agency",
            "food",
            "point_of_interest",
            "establishment"
         ],
         "vicinity" : "32 The Promenade, King Street Wharf 5, Sydney"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.870943,
               "lng" : 151.190311
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png",
         "id" : "e644f7f34cf875b9919c6548f1b721947362850a",
         "name" : "Lunch Cruise with Jazz on Sydney Harbour",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 292,
               "html_attributions" : [
                  "'u003ca href='"https://www.google.com/maps/views/profile/105423912060796272053'"'u003eFrom a Google User'u003c/a'u003e"
               ],
               "photo_reference" : "CmRdAAAAR4bqFTKYWdBwZwdBdON_JRD7V_joTwwIPwRUpZIZWkSSd8GQ3P2O-_aQbUJdL2RhoAyzCUIF0f--DI4oXFneTpj5zZfFq-iFiT7i_x0tjnDveIY8tJv-6o0uWSSjYqabEhCKqQWZqrKAoddjDcc64N48GhQZ2T1_ntPzNKCooHpZzlYQ7AxFOA",
               "width" : 438
            }
         ],
         "place_id" : "ChIJLfySpTOuEmsRPCRKrzl8ZEY",
         "reference" : "CoQBewAAAFd2fO_YWGTiT4RzXWb5tsOuOt7YyV_ScQOwm0tqJSrAyACCczeOzV-P_mgZLro1oKP_34Nt0nVC_1OEKAQUcd7cUm7xmAMSX-EkbSWiD0kOWGgGgKuDRtb0t_8qsxBGU_izugWCyK7SRWezTxELYNdkS0OEiSWPnvhxvXuQktBBEhAAtEe7fagW2kUR14T1QpVsGhQBO7YpIyYSPvo4zUJuL_bX30nJZw",
         "scope" : "GOOGLE",
         "types" : [ "bar", "restaurant", "food", "point_of_interest", "establishment" ],
         "vicinity" : "37 Bank St, Pyrmont"
      }
   ],
   "status" : "OK"
}