开发者

How do I add a marker to this google map code?

开发者 https://www.devze.com 2023-02-07 05:59 出处:网络
I would like to add a marker at the geocoded locatio开发者_StackOverflow社区n, how do I do that?

I would like to add a marker at the geocoded locatio开发者_StackOverflow社区n, how do I do that?

        function setMapAddress( address )
        {
            var geocoder = new google.maps.Geocoder();

            geocoder.geocode( { address : address }, function( results, status ) {
                if( status == google.maps.GeocoderStatus.OK ) {
                    var latlng = results[0].geometry.location;
                    var options = {
                        zoom: 8,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };

                    new google.maps.Map( document.getElementById( 'map_canvas2' ), options ); 

                }
            } );
        }

        setMapAddress( "{/literal}{$listing.City},{$listing.State}{literal}" );

Thanks


Add a variable to hold the reference to your map object, then add a marker:

var map = new google.maps.Map( document.getElementById( 'map_canvas2' ), options );
var marker = new google.maps.Marker({
    position: latlng, 
    map: map, 
    title: "Your location."
});  
0

精彩评论

暂无评论...
验证码 换一张
取 消