cordova-plugin-googlemaps
cordova-plugin-googlemaps copied to clipboard
Map styles via JSON
Is there no way to set the map style via json? Like the actual api's for google maps allows? If not then it could be very helpful... For example in my case i need to have night and day modes.. some of the night modes i can make on the wizard are very nice, and easy to make. Now I am having trouble trying to use them with this plugin :( Styling Wizard for Google Maps (Outputs JSON)
How the SDK's/API's originally did it: JS
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40.674, lng: -73.945},
zoom: 12,
styles: [
{elementType: 'geometry', stylers: [{color: '#242f3e'}]},
{elementType: 'labels.text.stroke', stylers: [{color: '#242f3e'}]},
{elementType: 'labels.text.fill', stylers: [{color: '#746855'}]},
{
featureType: 'administrative.locality',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'poi',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'poi.park',
elementType: 'geometry',
stylers: [{color: '#263c3f'}]
},
{
featureType: 'poi.park',
elementType: 'labels.text.fill',
stylers: [{color: '#6b9a76'}]
},
{
featureType: 'road',
elementType: 'geometry',
stylers: [{color: '#38414e'}]
},
{
featureType: 'road',
elementType: 'geometry.stroke',
stylers: [{color: '#212a37'}]
},
{
featureType: 'road',
elementType: 'labels.text.fill',
stylers: [{color: '#9ca5b3'}]
},
{
featureType: 'road.highway',
elementType: 'geometry',
stylers: [{color: '#746855'}]
},
{
featureType: 'road.highway',
elementType: 'geometry.stroke',
stylers: [{color: '#1f2835'}]
},
{
featureType: 'road.highway',
elementType: 'labels.text.fill',
stylers: [{color: '#f3d19c'}]
},
{
featureType: 'transit',
elementType: 'geometry',
stylers: [{color: '#2f3948'}]
},
{
featureType: 'transit.station',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'water',
elementType: 'geometry',
stylers: [{color: '#17263c'}]
},
{
featureType: 'water',
elementType: 'labels.text.fill',
stylers: [{color: '#515c6d'}]
},
{
featureType: 'water',
elementType: 'labels.text.stroke',
stylers: [{color: '#17263c'}]
}
]
});
IOS
import UIKit
import GoogleMaps
// Paste the JSON string to use.
let kMapStyle = "JSON_STYLE_GOES_HERE"
class ViewController: UIViewController {
// Set the status bar style to complement night-mode.
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func loadView() {
let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 12.0)
let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
do {
// Set the map style by passing a valid JSON string.
mapView.mapStyle = try GMSMapStyle(JSONString: kMapStyle)
} catch {
NSLog("The style definition could not be loaded: \(error)")
}
self.view = mapView
}
}
Sending a pull request, please.
Duplicate of #1109
See https://github.com/mapsplugin/cordova-plugin-googlemaps/issues/1180#issuecomment-261125046