【发布时间】:2017-07-14 15:39:34
【问题描述】:
我在 Ionic 2 的项目上工作,到目前为止我已经实现了地图,但我无法摆脱这一点。为了将 Google Place 和 Autocomplete 添加到项目中,我需要了解我应该采取的方式。
我能做什么?
HTML:
<ion-row>
<ion-item>
<ion-label>Search</ion-label>
<ion-input id="places" type="text" name="search"></ion-input>
</ion-row>
<div #map id="map"></div>
HOME.ts
export class HomePage {
public latitude: number;
public longitude: number;
@ViewChild('map') mapElement;
map: any;
marker: any;
search: string;
constructor(public navCtrl: NavController, public platform: Platform) {
/*platform.ready().then(() => {
this.InitMap();
});*/
}
ionViewDidLoad(){
this.InitMap();
}
InitMap() {
this.setLocation();
let input = document.getElementById('places');
let autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', () => {
let place = autocomplete.getPlace();
this.latitude = place.geometry.location.lat();
this.longitude = place.geometry.location.lng();
alert(this.latitude + ", " + this.longitude);
console.log(place);
});
}
setLocation() {
let latLng = new google.maps.LatLng(53.550513, 9.994241);
let mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
this.marker = new google.maps.Marker({
position: latLng,
map: this.map,
});
}
}
怎么了? 谢谢
【问题讨论】:
-
你到底在尝试什么,反应是什么?
-
正如我所说。我想实现地图的自动完成功能。
-
你得到了什么输出?
-
根本行不通。并且什么也不返回。我看不出有什么问题。
-
让我知道它是否有效
标签: javascript google-maps ionic-framework ionic2