确实GoogleMap 对象默认不显示所有地点。看来您应该使用 Google Places API 中的 Place Search 并通过附近的 URL 请求获取兴趣点列表:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=<LAT_LNG_e_g_ 32.944552,-97.129767>&types=point_of_interest&radius=<RADIUS_IN_METERS>&sensor=false&key=<YOUR_APP_KEY>
解析它并以编程方式在地图上显示所需的位置。
注意!附近的 URL 请求仅返回 20 个位置,要加载更多数据,您应该使用来自响应的 next_page_token 标记的字符串值,并通过 pagetoken 参数将其传递给下一个请求:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=<LAT_LNG_e_g_ 32.944552,-97.129767>&types=point_of_interest&radius=<RADIUS_IN_METERS>&sensor=false&key=<YOUR_APP_KEY>&pagetoken=<TOKEN_FOR_NEXT_PAGE_FROM_next_page_token_TAG_OF_RESPONSE>
在添加 POI 标记之前,您可能需要隐藏“标准”标记,例如 thisJozef 的答案:
只需修改地图样式即可:Adding a
Styled
Map
- 像这样创建 JSON 文件 src\main\res\raw\map_style.json:
[
{
featureType: "poi",
elementType: "labels",
stylers: [
{
visibility: "off"
}
]
}
]
- 将地图样式添加到您的
GoogleMap
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.map_style));
别忘了从Console 为您的应用程序启用 Places API。
或者,你可以做到这一点:使用简单的WebView 而不是MapFragment 并在必要的地方打开它:
WebView webview = (WebView) findViewById(R.id.web_view);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://maps.google.com/maps?q=32.944552,-97.129767&z=20");
WebView 显示与网络浏览器相同的兴趣点。