简体   繁体   中英

Google Maps Api Get Details Request Not Working

I am having trouble to make a google map, whenever the user clicks on the marker, I would like them to see a info window with images. I have been able to do everything, but for the images, I tried a Get details request, and for some reason it didn't work.

function createMapMarker(placeData) {
    count++;
    var lat = placeData.geometry.location.lat();    
    var lon = placeData.geometry.location.lng();    
    var name = placeData.formatted_address;     
    var bounds = window.mapBounds;
    position = placeData.geometry.location;
    var marker = new google.maps.Marker({
        map: map,
        position: position,
        title: name
    });
    bounds.extend(new google.maps.LatLng(lat, lon));
    map.fitBounds(bounds);
    map.setCenter(bounds.getCenter());
    getDetails();
    function getDetails() {
        var service = new google.maps.places.PlacesService(map);
        var request = {
            placeId: placeData.place_id
        }
        service.getDetails(request, getCallBack);
    }
    function getCallBack(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            infowindow(results[0]);
        }
    }
    function infowindow(place) {
        var infowindow = new google.maps.InfoWindow();
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent("<img src='"+place.photos[0].getUrl+"'><br>"+placeData.name+"<br>"+placeData.formatted_address+"<br>Rating:"+placeData.rating+" stars<br>");
            infowindow.open(map, this);
        });   
    }
}

To get images to show on the 'Window' once clicked on the marker you could do:

infowindow.imageView.image = UIImage(named: "image.jpg").

Hope this helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM