账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    ionic googleMaps
    62
    0

    ionic3 项目中 需要googgle地图 国外的项目 但是之前没接触过地图类,想知道谷歌地图 怎么实现 获取本地位置 计算两点之间的距离 等等 希望大神能指导一下 卡了举哀半个月了 一点发都没有 基于ionic3

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 習慣了孤單 普通会员 1楼

      To use Google Maps in Ionic, you'll need to follow these steps:

      1. Add the Google Maps plugin to your Ionic project by adding the following line to your app.module.ts file:

      ```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 { } ```

      1. In your google-map.component.ts file, import the GoogleMap module 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(); } } ```

      1. In your google-map.component.html file, 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>

      1. In your google-map.service.ts file, 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}); } } ```

      1. In your app.module.ts file, import the GoogleMapService and 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 { } ```

      1. Start your Ionic project and navigate to the google-map page. You should now see the Google Maps marker on the map.

      That's it! You've successfully used Google Maps in your Ionic project.

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部