Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...