nativescript-google-maps-sdk use native calls to style the map

ⅰ亾dé卋堺 提交于 2020-01-07 09:33:28

问题


I successfully integrated a google map at my angular2+nativescript project. Everything I needed from the typescript definition file is working for me.

However, I wanted to play around with the styling of the map. AFAIK, I have to use native calls to the map, as the method setMapStyle() is not in the typescript definition.

I thought I could use the gMap property to access the native object and call the method. But I fail in setting up the right parameter as requested in google docs (https://developers.google.com/maps/documentation/android-api/styling) as I dont know how to create a MapStyleOptions object. The type is unknown.

Anyone tried or succeeded in this task yet and want to share some hints? How would you access native GoogleMap?


回答1:


NativeScript allows you to access all public API of plugins used in the app, therefore you should be able to make native calls to the Map API as per the documentation at nativescript.org

If you want to create a MapStyleOptions object for example, you'd write

var MapStyleOptions : any = com.google.android.gms.maps.model.MapStyleOptions;
var mapStyle : any = new MapStyleOptions({"..":".."});

or just var mapStyle = new com.google.android.gms.maps.model.MapStyleOptions({"..":".."});

When TypeScript complains about com.google... not being recognized, you can either define it as any or import some ready to use typings. Good luck!



来源:https://stackoverflow.com/questions/40153208/nativescript-google-maps-sdk-use-native-calls-to-style-the-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!