使用NativeScript在iOS上设置Google地图样式

时间:2017-06-01 18:00:10

标签: ios google-maps nativescript angular2-nativescript

我目前正在使用this插件在我的NativeScript应用中集成Google Maps。他们有办法更新Android (shown here)的地图样式,但我找不到任何代码来更新iOS上的地图样式。

我还发现this之前有人问过这个问题,但没有提到任何iOS细节。

我还发现这些文档引用了gMAP的iOS使用,但我不知道如何使用这些信息来使其在我的NativeScript应用程序中运行。

有没有人在iOS上成功更改了地图的颜色?

这是我目前的代码:

import { MapStyles } from "./map-style";
declare var com:any; //Typescript workaround

onMapReady(args): void {
    this.mapView = args.object;

    if (isAndroid) {
        this.mapView.gMap.setMapStyle(new com.google.android.gms.maps.model.MapStyleOptions(JSON.stringify(MapStyles)));
    }

    if (isIOS) {
        // style map for iOS
    }
}

1 个答案:

答案 0 :(得分:0)

我能够使用相同的代码为iOS和Android设置样式:

this.mapView.setStyle(<Style>JSON.parse(this.currentMapStyle));

注意: Style类是从nativescript-google-maps-sdk导入的 this.currentMapStyle是我使用以下代码生成的字符串成员:https://mapstyle.withgoogle.com/

修改
我正在使用带有Angular2的Nativescript和nativescript-google-maps-sdk的1.4.3版本。我的onMapReady函数如下所示:

private onMapReady(args): void {
    this.mapView = args.object;
    let mapStyle = '[{"elementType":"geometry","stylers":[{"color":"#242f3e"}]},{"elementType":"labels.text.fill","stylers":[{"color":"#746855"}]},{"elementType":"labels.text.stroke","stylers":[{"color":"#242f3e"}]},{"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"}]}]'

    this.mapView.setStyle(<Style>JSON.parse(mapStyle));
}