In an app using Google Maps JavaScript API, I need to obtain the bookmarks from a JSON file, importing the relevant plugins I found a tutorial that works, I need to do geolocation, but no allows to use loadMap but displayGoogleMap , I'll leave the code below.
export class HomePage {
@ViewChild('mapContainer') mapContainer: ElementRef;
map: any;
constructor(public navCtrl: NavController, public http: Http) {
}
ionViewWillEnter() {
this.displayGoogleMap();
this.getMarkers();
}
displayGoogleMap() {
let latLng = new google.maps.LatLng(57.8127004, 14.2106225);
let mapOptions = {
center: latLng,
disableDefaultUI: true,
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(this.mapContainer.nativeElement, mapOptions);
}
getMarkers() {
this.http.get('assets/data/markers.json')
.map((res) => res.json())
.subscribe(data => {
this.addMarkersToMap(data);
});
}
addMarkersToMap(markers) {
for(let marker of markers) {
var position = new google.maps.LatLng(marker.latitude, marker.longitude);
var miMarker = new google.maps.Marker({position: position, title: marker.title});
miMarker.setMap(this.map);
}
}
}