开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜