我在CN1应用程序中使用了一张地图。为了在我的表单中注入地图,我使用这种类型:
MapContainer mapContainer = new MapContainer();
我的应用只能在IPad标签上运行。我可以正确查看我的Google地图。但我需要设计这张地图的样式。使用Javascript我可以这样做:
var styles = [
{
featureType: "administrative.country",
elementType: "labels",
stylers: [ { color: '#f24547' } ]
}
];
map = new google.maps.Map( document.getElementById('map'), {
center: navigationData.googlePosition,
zoom: 15
});
map.setOptions( { styles: styles } );
我如何在CN1 java代码中执行相同操作?
提前致谢。
答案 0 :(得分:1)
您无法像Codename One中那样更改原生Google地图的样式,但您可以设置地图类型,缩放级别,中心位置和当前位置。
MapContainer mapContainer = new MapContainer();
mapContainer.setMapType(MapContainer.MAP_TYPE_HYBRID);
mapContainer.setShowMyLocation(true);
LocationManager lm = LocationManager.getLocationManager();
Location loc = lm.getLastKnownLocation();
if (lm.isGPSDetectionSupported()) {
if (lm.isGPSEnabled()) {
Location loc2 = lm.getCurrentLocationSync(20000);
if (loc2 != null) {
loc = loc2;
}
} else {
Dialog.show("", "MyAppName needs access to your current location, please enable GPS in Settings.", "Ok", null);
}
} else {
Location loc2 = lm.getCurrentLocationSync(20000);
if (loc2 != null) {
loc = loc2;
}
}
mapContainer.zoom(new Coord(loc.getLatitude(), loc.getLongitude()), 15);