gpt4 book ai didi

java - Android - 获取附近地点的列表

转载 作者:行者123 更新时间:2023-12-02 05:31:51 24 4
gpt4 key购买 nike

我需要能够在我的应用程序中获取附近地点的列表。我也希望它位于 NavigationDrawer 内。就像 Google Now 的附近地点卡一样:

Google Now card

虽然我希望将其包装在 NavigationDrawer 中。有办法做到这一点吗?

谢谢。

最佳答案

Google Places API 是一项基于网络的服务,因此您需要将请求发送至:

https://maps.googleapis.com/maps/api/place/search/json
?location=COORDINATES_IN_LAT_LONG
&radius=DISTANCE_IN_METERS
&key=YOUR_API_KEY

您将返回的结果将采用 JSON 格式,使用 GSON 可以轻松解析该结果。 :

{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 37.79593620000001,
"lng" : -122.40000320
},
"viewport" : {
"northeast" : {
"lat" : 37.80475270,
"lng" : -122.38399580
},
"southwest" : {
"lat" : 37.78711860,
"lng" : -122.41601060
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7498697d87cb1a28280277cb7825e0a4c21387d6",
"name" : "Financial District",
"reference" : "CoQBegAAAFrgJ9ZyeZrV_a9QWteNl9hrNGq-9qhPIP0M9yIL00HhKzBJNERhX95nEnAAtgBKqc2e51Yq2-OG3g-D8YZ20pcFKK7n3Pipd3Rpz7JmFedlg-gimYv3YGhOYVhblHYhhJM8y48J7tbDT4QPKsnumhsyhTf-5YktikanlFKt3NKNEhDwKmUyXRDhsYS1-rzHCZSRGhQP5VmDcuvvxvYE7e7dC-0PWYhfjw",
"types" : [ "neighborhood", "political" ],
"vicinity" : "San Francisco"
},
{
"geometry" : {
"location" : {
"lat" : 37.7856560,
"lng" : -122.4012520
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/art_gallery-71.png",
"id" : "5e693f5ae4f1cd1512732b1568ff0e4b67ab0291",
"name" : "San Francisco Museum of Modern Art",
"rating" : 4.30,
"reference" : "CpQBgQAAAO9fVOGklWz3ugJeJ0DuVibD60yFJ_z19hm5Cm7f4NYsIECaVqC2yhQ746w2vMmAJmA-jYNNwp5_ot7hsRxVmcbO1TdvBtYG3LZ6JD2vxgMXSCFK3U2McAywoOsbPwjU-9fN6jtHmvuiCXNDamIUP4IX462NsmyO06digENJcMoLES75jTTvVBjuRvNFRdIJnRIQDtf7lhNra8eTmAYy1PKKnhoU7hDZ-Y6TB8HRnHBsVDnsWnL5E0o",
"types" : [ "art_gallery", "store", "establishment" ],
"vicinity" : "151 Third Street, San Francisco"
},
{
"geometry" : {
"location" : {
"lat" : 37.7791590,
"lng" : -122.4158080
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/library-71.png",
"id" : "b1c83827c82c9fa59ffcdad652d1e8a1b04a4ae8",
"name" : "San Francisco Public Library",
"rating" : 4.20,
"reference" : "CoQBewAAAP-wCLLWVV2kys-vTPPr9LZPUkZXqrUUjG6LTRmcVARlehuh_SkvisDlH5X6WgoX6BG16e7RSS94xxhZbj0B3i7gC1KFDz_Oc88hK6YUj3w8Ix0N5M6UmKfAIXq1CYXLMrt_KAR7WsNF65MiSnj-Nqu0AMxwW-dMvRfmHOk7xGW0EhCyRZgNzYmPV08XAHZ-HBx_GhQYlLxuAU4MH8FvkdMWbQ1Xvf7WxA",
"types" : [ "library", "establishment" ],
"vicinity" : "100 Larkin Street, San Francisco"
},

然后,如果您愿意,可以将其传递到抽屉导航的适配器。如果即使在离线模式下您也想在抽屉导航中显示此数据,请将此数据缓存在 txt 文件中,并在启动应用程序时读取它。这还有一个额外的优点,即仅在用户选择时才刷新此数据,从而节省带宽。

如果您希望地点按距离排名,请将 &rankby=distance 添加到您的请求网址。

Source

关于java - Android - 获取附近地点的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25458036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com