如何在标记点击上获得标记选项?

问题描述 投票:0回答:1

我在离子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点击标记是可能我找不到任何关于它。

angular ionic3 google-maps-markers ionic4
1个回答
1
投票

在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;
        });
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.