建议的github问题解决方案
我是离子应用开发的初学者。
我正在从API纬度和经度中获得回应,并且将其传递到Google地图中以将标记放入地图中。但是我遇到了错误
错误:typeError:_this._objectInstance.remove不是函数。
此类型脚本代码
getLocation(item){
console.log(item.Street);
var headers = new Headers();
headers.append('Content-Type', 'application/json' );
headers.append("Accept", 'application/json');
let options = new RequestOptions({ headers: headers });
let postParams = {
Street: "fortesting",
City: "string",
zipORpincode: "string",
DistrictORcounty: "string",
State: "string",
Country: "string"
}
this.http.post('http://link of an API',postParams, options)
.subscribe(
res => {
let dataTemp = res.json(); //dataTemp is the json object you showed me
this.Longitude = dataTemp.Longitude; //contains a [] object with all yours users
this.Latitude = dataTemp.Latitude;
console.log(this.Longitude);//This is for log
console.log(this.Latitude );//This is for log
let mapOptions: GoogleMapOptions = {
camera: {
target: {
lat: this.Latitude,
lng: this.Longitude
},
zoom: 18,
tilt: 30
}
};
this.map = GoogleMaps.create('map_canvas', mapOptions);
// Wait the MAP_READY before using any methods.
this.map.one(GoogleMapsEvent.MAP_READY)
.then(() => {
console.log('Map is ready!');
// Now you can use all methods safely.
this.map.addMarker({
title: 'Ionic',
icon: 'blue',
animation: 'DROP',
position: {
lat: this.Latitude,
lng: this.Longitude
}
})
.then(marker => {
marker.on(GoogleMapsEvent.MARKER_CLICK)
.subscribe(() => {
alert('clicked');
});
});
});
},
err => {
console.log(err);
}
);
}
这是我正在调用功能的HTML代码
<button ion-button block menuToggle="right" color="menu-o"
(click)='getLocation(results)'>
<div>
<ion-icon name="create"></ion-icon>
<label>Get Location</label>
</div>
</button>
假设map_canvas
是需要创建地图的HTML元素的ID,您需要将元素传递到创建函数中,而不仅仅是ID。
您可以使用ViewChild
。
声明类变量
@ViewChild('map_canvas') mapElement;
发送本地元素
this.map = GoogleMaps.create(this.mapElement.nativeElement, mapOptions);
来源: @faisalali23