I have ionic app using angular . l am trying to get objects from JSon API url , content on latitude and longitude from server . The data json api content on Object keys and those keys are change all time . l want to get only the coordinates inside of those Object keys and add it to google map marker to shows on map .
my code
export class HomePage implements OnInit {
point:any
Data :any
map: GoogleMap;
constructor(private http : HTTP) {}
ngOnInit(){
this.getData()
}
//// Getting json response ////
getData(){
this.http.get("xxxxxxx", {}, {}).then(data =>{
this.Data = JSON.parse(data.data)
this.point= Object.keys(this.Data).map(key => this.Data[key].airport.position).map(({
latitude,
longitude
}) => ({
lat: latitude,
lng: longitude
}))
console.log(this.point)
}).then(()=>{
this.loadMap()
})
}
//// inject coordinates into google map ////
loadMap() {
this.map = GoogleMaps.create('map_canvas');
////// icon marker here ////
let marker: Marker = this.map.addMarkerSync({
title: 'Ionic',
icon: 'blue',
animation: 'DROP',
position: this.point
});
}
}
short Json
{
"ABQ": {
"airport": {
"name": "Albuquerque International Airport",
"code": {
"iata": "ABQ",
"icao": "KABQ"
},
"position": {
"latitude": 35.040218,
"longitude": -106.609001,
"altitude": 5355
}
}
},
"ACE": {
"airport": {
"name": "Lanzarote Airport",
"code": {
"iata": "ACE",
"icao": "GCRR"
},
"position": {
"latitude": 28.945459,
"longitude": -13.6052,
"altitude": 47
}
}
}
}
FULL Json url
when l run my app l got nothing on map no markers at all , also no errors shows in console .
Google map plugin doc
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…