2017-02-19 25 views
1

我在我的CN1应用程序中使用了一张地图。为了在我的表单中注入地图,我使用这种类型:如何在Codename One API下设计Google Map?

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代码中做同样的事情?

在此先感谢。

回答

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); 
+1

对于完整性我还提到,你可以用叉子叉[谷歌地图代号一个端口(https://github.com/codenameone/codenameone-google-maps/)和做款式变化有 –