nativescript-google-maps-sdk使用本地调用来设置地图的样式 [英] nativescript-google-maps-sdk use native calls to style the map

查看:150
本文介绍了nativescript-google-maps-sdk使用本地调用来设置地图的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功在我的angular2 + nativescript项目中整合了谷歌地图。我从打字稿定义文件中得到的所有东西都在为我工作。



但是,我想玩弄地图的样式。 AFAIK,我必须使用本地调用映射,因为setMapStyle()方法不在typescript定义中。



我想我可以使用gMap属性来访问本地对象并调用该方法。但是我无法按照google文档中的要求设置正确的参数( https:// developers.google.com/maps/documentation/android-api/styling ),因为我不知道如何创建MapStyleOptions对象。该类型是未知的。



任何人尝试或成功完成此任务,并想分享一些提示?你将如何访问本地GoogleMap?

解决方案

NativeScript允许您访问应用中使用的插件的所有公共API,因此您应该能够根据上的文档进行本地调用Map API nativescript.org



例如,如果您想创建一个MapStyleOptions对象,您可以编写

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

或者只是 var mapStyle = new com.google.android.gms.maps当TypeScript抱怨 com.google ... 不被识别,您可以将其定义为任何或导入一些准备使用的类型。
祝你好运!


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?

解决方案

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!

这篇关于nativescript-google-maps-sdk使用本地调用来设置地图的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆