简体   繁体   English

离子谷歌地图电容器

[英]Ionic Google Maps Capacitor

Can I use this Ionic Google Maps plug-in with capacitor( https://github.com/mapsplugin/cordova-plugin-googlemaps-doc )?我可以使用这个带电容器的 Ionic Google Maps 插件( https://github.com/mapsplugin/cordova-plugin-googlemaps-doc )吗? I Try我试试

npm install cordova-plugin-googlemaps npm install @ionic-native/googlemaps npm 安装cordova-plugin-googlemaps npm 安装@ionic-native/googlemaps

But without success.但没有成功。 How I install it with capacitor?我如何安装它与电容器? And how I get the current position?以及如何获得当前的 position? I'm using Angular.我正在使用 Angular。

I need use it because the native Geolocation does't work with old Android versions.我需要使用它,因为原生地理定位不适用于旧的 Android 版本。

Specific for Capacitor , google maps works perfectly.特定于电容器,谷歌地图完美运行。

I would suggest you follow this tutorial .我建议您按照本教程进行操作。 You can ignore the nativegeocoder implementation in the tutorial if you don't need it.如果不需要,可以忽略本教程中的 nativegeocoder 实现。

The above tutorial is based on including the javascript api in your index.html file and then referencing it in your code.上面的教程基于在 index.html 文件中包含 javascript api 然后在代码中引用它。

Works perfectly with all the functionalities mentioned in the google javascript docs.与谷歌 javascript 文档中提到的所有功能完美配合。

There are two ways of implementing google maps in an ionic capacitor app.在离子电容器应用程序中有两种实现谷歌地图的方法。

  1. Using a cordova plugin (which integrates google maps native SDK)使用 cordova 插件(集成了谷歌地图原生 SDK)
  2. Using the google maps javascript API使用谷歌地图 javascript API

Read this article to understand the difference 阅读本文以了解差异

Another tutorial for implementing google maps 另一个实现谷歌地图的教程

Do not forget to put this after you import statements in your.ts file where you need to access the map.不要忘记在您需要访问 map 的 your.ts 文件中导入语句后将其放入。

declare var google;声明 var google;

Once you have integrated it like it is done in the tutorial, for Google geolocation, add this..一旦你像在教程中那样集成了它,对于谷歌地理定位,添加这个..

this.googleGeocoder = new google.maps.Geocoder();
this.googleGeocoder.geocode({'location': latlng},(results,status)=>{
  if (status === 'OK') {
     // do your stuff
  }
})

You mistyped the package name, it is @ionic-native/google-maps , not @ionic-native/googlemaps .您打错了 package 名称,它是@ionic-native/google-maps ,而不是@ionic-native/googlemaps Also, if you are using @ionic-native/google-maps , you don't need to install the other package.此外,如果您使用的是@ionic-native/google-maps ,则无需安装其他 package。

For installation, first you must create Google Maps API keys.对于安装,首先您必须创建 Google Maps API 密钥。

Then, run:然后,运行:

npm install @ionic-native/core@beta @ionic-native/google-maps@beta

ionic cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#multiple_maps --variable API_KEY_FOR_ANDROID="..." --variable API_KEY_FOR_IOS="..."

replacing the ... s with your API keys.用您的 API 密钥替换... s。

Regarding getting the current position, you need to use LocationService.getMyLocation() to get the current location.关于获取当前position,需要使用LocationService.getMyLocation()获取当前位置。 Here is the documentation and a tutorial. 是文档和教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM