- 62
- 0
ionic3 项目中 需要googgle地图 国外的项目 但是之前没接触过地图类,想知道谷歌地图 怎么实现 获取本地位置 计算两点之间的距离 等等 希望大神能指导一下 卡了举哀半个月了 一点发都没有 基于ionic3
- 共 0 条
- 全部回答
-
習慣了孤單 普通会员 1楼
To use Google Maps in Ionic, you'll need to follow these steps:
- Add the Google Maps plugin to your Ionic project by adding the following line to your
app.module.tsfile:
```typescript import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { GoogleMapsModule } from '@ionic-native/google-maps'; import { IonicModule } from '@ionic-native/http'; import { AppComponent } from './app.component'; import { GoogleMapComponent } from './google-map/google-map.component';
@NgModule({ declarations: [ AppComponent, GoogleMapComponent ], imports: [ BrowserModule, IonicModule.forRoot(), GoogleMapsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } ```
- In your
google-map.component.tsfile, import theGoogleMapmodule and create a reference to it:
```typescript import { Component } from '@angular/core'; import { GoogleMap } from '@ionic-native/google-maps';
@Component({ selector: 'app-google-map', templateUrl: './google-map.component.html', styleUrls: ['./google-map.component.css'] }) export class GoogleMapComponent { map: GoogleMap;
constructor(private mapService: GoogleMapService) { this.map = this.mapService.get mapOptions(); } } ```
- In your
google-map.component.htmlfile, you can add the following code to display the Google Maps marker:
html <google-map options="mapOptions" [center]="mapCenter" [zoom]="mapZoom"> <google-map-marker *ngFor="let marker of markers" (click)="onMarkerClick(marker)"> {{ marker.text }} </google-map-marker> </google-map>- In your
google-map.service.tsfile, create a method that will be called when the marker is clicked:
```typescript import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators';
@Injectable({ providedIn: 'root' }) export class GoogleMapService { private mapOptions: any;
constructor() { this.mapOptions = { center: { lat: 37.7749, lng: -122.4194 }, zoom: 8 }; }
get mapOptions(): any { return this.mapOptions; }
set mapOptions(value: any) { this.mapOptions = value; }
onMarkerClick(marker: any) { console.log(
Marker clicked at ${marker.lat}, ${marker.lng}); } } ```- In your
app.module.tsfile, import theGoogleMapServiceand register it as a provider:
```typescript import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { GoogleMapsModule } from '@ionic-native/google-maps'; import { IonicModule } from '@ionic-native/http'; import { AppComponent } from './app.component'; import { GoogleMapService } from './google-map.service'; import { GoogleMapComponent } from './google-map/google-map.component';
@NgModule({ declarations: [ AppComponent, GoogleMapComponent ], imports: [ BrowserModule, IonicModule.forRoot(), GoogleMapsModule ], providers: [GoogleMapService], bootstrap: [AppComponent] }) export class AppModule { } ```
- Start your Ionic project and navigate to the
google-mappage. You should now see the Google Maps marker on the map.
That's it! You've successfully used Google Maps in your Ionic project.
- Add the Google Maps plugin to your Ionic project by adding the following line to your
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
