【发布时间】:2020-01-21 03:32:57
【问题描述】:
我正在开发一个 Ionic 项目,该项目的要求是在具有多个标记的 ionic 页面中添加谷歌地图。我遵循了一些 youtube 教程,并成功添加了带有一个位置标记的谷歌地图。我想添加多个具有不同纬度和经度值的位置标记。
下面是我试过的代码。
HTML:
<ion-content>
<div #mapElement class="map"></div>
</ion-content>
TS:
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
declare var google;
@Component({
selector: 'app-test',
templateUrl: './test.page.html',
styleUrls: ['./test.page.scss'],
})
export class TestPage implements OnInit {
@ViewChild('mapElement', {static:true}) mapRef: ElementRef;
constructor() { }
ngOnInit() {
}
ngAfterViewInit() {
const location = new google.maps.LatLng(17.385044,
78.486671);
const options = {
center:location,
zoom:10,
streetViewControl:false,
mapTypeId:'hybrid'
};
const map = new google.maps.Map(this.mapRef.nativeElement,options);
this.addMarker(location,map);
}
addMarker(position,map) {
return new google.maps.Marker({
position,
map
});
}
}
请帮助我如何为班加罗尔、钦奈、孟买位置添加不同的标记及其纬度和经度值。
谢谢。
【问题讨论】:
-
谢谢@andypotato,我会试试这个,让你知道
-
嗨@andypotato,它不适合我。我是离子的新手。你能帮忙写几盎司的代码吗?谢谢
标签: ionic4