mapbox react native 直接使用会出现部分地图语言翻译不全,有大量拼音label,本文讲解如何解决这个问题:
首先地图使用URL使用以下版本:
mapbox://styles/mapbox/streets-v10
mapbox://styles/mapbox/outdoors-v10
mapbox://styles/mapbox/dark-v9
mapbox://styles/mapbox/light-v9
mapbox://styles/mapbox/satellite-streets-v9
mapbox://styles/mapbox/traffic-day-v2
mapbox://styles/mapbox/traffic-night-v2
然后修改源码,路径 node_modules@react-native-mapbox-glmapsandroid
ctmglsrcmainjavacommapbox
ctmglcomponentsmapviewRCTMGLMapView.java
private void setupLocalization(Style style) {
mLocalizationPlugin = new LocalizationPlugin(RCTMGLMapView.this, mMap, style);
if (mLocalizeLabels) {
try {
mLocalizationPlugin.matchMapLanguageWithDeviceDefault();
localizationPlugin.setMapLanguage(MapLocale.CHINA);//可以根据需要修改,或者动态的设置语言
} catch (Exception e) {
final String localeString = Locale.getDefault().toString();
Logger.w(LOG_TAG, String.format("Could not find matching locale for %s", localeString));
}
}
}