2017-02-19 4 views
1

Ich verwende eine Karte in meiner CN1-Anwendung. Für die Karte in meiner Form zu injizieren, ich benutze diese Art:Wie style eine Google Map unter Codename One API?

MapContainer mapContainer = new MapContainer(); 

Meine App nur auf einem iPad Tab ausgeführt werden muss. Ich kann meine Google-Karte richtig anzeigen. Aber ich muss diese Karte stylen. Mit Javascript kann ich Folgendes tun:

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 }); 

Wie kann ich das gleiche in meinem CN1 Java-Code tun?

Vielen Dank im Voraus.

Antwort

1

Sie können die Stile der nativen Google Map nicht wie in Codename One ändern, aber Sie können den Kartentyp, die Zoomstufe, die Mittelposition und den aktuellen Standort festlegen.

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

Der Vollständigkeit ich auch möchte erwähnen, dass Sie die [Google Maps Codename Ein Port] kann Gabel (https://github.com/codenameone/codenameone-google-maps/) und Stil zu tun Änderungen gibt –