我在离子4工作并使用谷歌地图api。我有几个标记,我建立像这样:
setRestaurantMarkers() {
const markers = [];
this.singletonService.restaurants.results.map(restaurant => {
const restaurantPosition = {lat: restaurant['Restaurant'].Lat, lng: restaurant['Restaurant'].Long};
this.markerOptions = new Marker({
position: restaurantPosition,
title: restaurant['Restaurant'].Name,
category: restaurant['RestaurantCategory'].Name,
map: this.map
});
this.marker = new google.maps.Marker(this.markerOptions);
this.marker.addListener('click', (marker) => {
// Set destination for navigate button
this.destination = [marker.latLng.lat(), marker.latLng.lng()];
console.log(marker.latLng.lat(), marker.markerOptions);
this.markerClicked = true;
});
});
}
但是当我点击标记时,我无法获得markerOptions
的详细信息。我希望有这个markerOptions
点击标记是可能我找不到任何关于它。
在var而不是class属性中指定标记选项
setRestaurantMarkers() {
const markers = [];
this.singletonService.restaurants.results.map(restaurant => {
const restaurantPosition = {lat: restaurant['Restaurant'].Lat, lng: restaurant['Restaurant'].Long};
const markerOptions = new Marker({ // make it as const
position: restaurantPosition,
title: restaurant['Restaurant'].Name,
category: restaurant['RestaurantCategory'].Name,
map: this.map
});
this.marker = new google.maps.Marker(markerOptions);
this.marker.addListener('click', (marker) => {
// Set destination for navigate button
this.destination = [marker.latLng.lat(), marker.latLng.lng()];
console.log(marker.latLng.lat(), markerOptions); // get directly
this.markerClicked = true;
});
});
}