gpt4 book ai didi

android - google mapView 样式不适用于 maptype=TERRAIN 的 Android

转载 作者:行者123 更新时间:2023-11-29 16:33:01 26 4
gpt4 key购买 nike

使用这个 stackoverflow question ,我尝试将一些自定义样式应用于 Android map View 。

造型基本上就是把水弄黑

mapstyle_json.js:

[
{
featureType: 'water',
elementType: 'geometry',
stylers: [{color: '#000000'}]
},
{
featureType: 'water',
elementType: 'labels.text.fill',
stylers: [{color: '#515c6d'}]
},
{
featureType: 'water',
elementType: 'labels.text.stroke',
stylers: [{color: '#17263c'}]
}
]

我的主要 Activity :

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final MapView mapView = (MapView) findViewById(R.id.mapView);
final android.content.Context context = this;

mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {

@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // Without this line, the styling works as intended
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
context, R.raw.mapstyle_json));

if (!success) {
Log.e("1", "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e("1", "Can't find style. Error: ", e);
}
Log.d("1", "onMapReady: something");
LatLng coordinates = new LatLng(45.832119, 6.865575);
googleMap.addMarker(new MarkerOptions().position(coordinates).title("hello"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 12));
mapView.onResume();
}
});
}
}

在不设置 map 类型(使用默认 map 类型)的情况下,样式会正常工作。考虑到链接问题,应该可以设置 TERRAIN 类型 map 的样式。 (也许只使用 javascript)。

为什么这种样式没有应用于地形类型 map ?在 Android mapView 中可以吗?

编辑:

代码基于谷歌自己的指南,原始资源用例:https://developers.google.com/maps/documentation/android-sdk/styling

也许这是一个 google API v2 与 v3 的问题。据我了解,Android 使用 API v2。链接的问题是关于 v3

最佳答案

似乎是它的预期行为。来自 Official Documentation :

Styling works only on the normal map type.

Normal map type是:

Typical road map. Shows roads, some features built by humans, and important natural features like rivers. Road and feature labels are also visible.

关于android - google mapView 样式不适用于 maptype=TERRAIN 的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820851/

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