问题
I want to get lat-long co-ordination when user clicks on map. However, when I tried to do so I’m getting an error like the following:
_this.map.on is not a function.
I have also tried this.map.one but still I’m getting the same error. Can any one help me? to set an on click event on map and get lat-long from map which is JavaScript API based (not native) used on browser.
I am also getting the following error in setClickable:
_this.map.setClickable is not a function.
Here is my code:
initMap() {
this.mapInitialised = true;
this.geolocation.getCurrentPosition().then((position) => {
console.log("lat " + position.coords.latitude + " long " + position.coords.longitude)
let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
let mapOptions = {
center: latLng,
zoom: 15,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
clickableIcons: false,
disableDefaultUI: true,
zoomControl: false,
}
this.map = new google.maps.Map(document.getElementById("map"), mapOptions);
var longClick = google.maps.event.MAP_CLICK;
this.map.on(longClick, function (latLng) {
var selectedLatLocation = latLng.lat.toString();
var selectedLongLocation = latLng.lng.toString();
alert(selectedLatLocation + " " + selectedLongLocation);
});
this.map.one(google.maps.event.MAP_READY)
.then(() => {
console.log('Map is ready!');
this.map.on(google.maps.event.MAP_CLICK).subscribe(
(data) => {
alert("Click MAP");
}
);
});
this.map.setClickable(true);
});
}
来源:https://stackoverflow.com/questions/49977992/map-setclickable-is-not-a-function-in-ionic