谷歌地图随着离子电流3位置标记

问题描述 投票:0回答:1

我建立中,我想使用谷歌地图的应用程序,我使用的离子版本3.20.1和科尔多瓦版本8.xx

我想使用谷歌地图Java脚本API,使我的地图看起来像它看起来大部分的应用。屏幕截图 - 我想建什么i want it to be like this我能建this is where i reached

我的地图.html文件看起来像

<ion-header>
  <ion-navbar>
    <ion-title>
      Map
    </ion-title>
    <ion-buttons end>
      <button ion-button (click)="addMarker()"><ion-icon name="add"></ion- 
icon>Add Marker</button>
    </ion-buttons>  
  </ion-navbar>
</ion-header>

<ion-content>
  <div #map id="map"></div>  
</ion-content>

我map.ts文件

import { Component, ViewChild, ElementRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';

declare var google;

@IonicPage()
@Component({
  selector: 'page-google-map',
  templateUrl: 'google-map.html',
})
export class GoogleMapPage {
  @ViewChild('map') mapElement: ElementRef;
  map: any;

  constructor(public navCtrl: NavController, public navParams: 
NavParams,public geolocation: Geolocation) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad GoogleMapPage');
    this.loadMap();
  }

  loadMap(){

this.geolocation.getCurrentPosition().then((position) => {

  let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

  let mapOptions = {
    center: latLng,
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
  this
}, (err) => {
  console.log(err);
});

  }
      addMarker(){

    let marker = new google.maps.Marker({
      map: this.map,
      animation: google.maps.Animation.DROP,
      position: this.map.getCenter()
    });

    let content = "<h4>Information!</h4>";          

    this.addInfoWindow(marker, content);

  }
      addInfoWindow(marker, content){

    let infoWindow = new google.maps.InfoWindow({
      content: content
    });

    google.maps.event.addListener(marker, 'click', () => {
  infoWindow.open(this.map, marker);
    });

  }
 }

我强烈需要一个蓝点显示当前位置

google-maps-api-3 ionic3
1个回答
1
投票

看看在这里下复杂图标的谷歌地图API参考:https://developers.google.com/maps/documentation/javascript/markers#complex_icons

您可以设置自定义标记与SVG图标是一个蓝点。下面是从需要的用户位置自定义图标以前离子项目的例子。注意SVG是不是整个文件,只是路径信息。我想你也可以通过URL引用一个完整的SVG文件(请参阅参考资料)。在这个例子中,SVG路径不是一个点。

var myLocationIcon = {
  path: 'M11 11l1.256 5 3.744-10-10 3.75 5 1.25zm1-11c-5.522 0-10 4.395-10 9.815 0 5.505 4.375 9.268 10 14.185 5.625-4.917 10-8.68 10-14.185 0-5.42-4.478-9.815-10-9.815zm0 18c-4.419 0-8-3.582-8-8s3.581-8 8-8 8 3.582 8 8-3.581 8-8 8z',
  scale: 1,
  fillColor: '#3a84df'
};

var marker = new google.maps.Marker({
  map: map,
  animation: google.maps.Animation.DROP,
  position: latlng,
  icon: myLocationIcon
});
© www.soinside.com 2019 - 2024. All rights reserved.