user1652238
user1652238

Reputation: 1

Error with markers

am trying to put a marker on a map of a location , but it give me error the options , but if i load the map alone it works fine

hier is my code

<script type="text/javascript">
    //var map;
    function initialize() {  if (GBrowserIsCompatible()) {
            var lat = parseFloat(document.getElementById("FormView1_LatitudeLabel").textContent);
            var lng = parseFloat(document.getElementById("FormView1_LongitudeLabel").textContent);


            // Creating a map

                    // Creating a LatLng object containing the coordinate for the center of the map  
                    var latlng = new google.maps.LatLng(lat, lng);
                    // Creating an object literal containing the properties we want to pass to the map  
                    var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                    };
                    // Calling the constructor, thereby initializing the map  
                    var map = new google.maps.Map(document.getElementById('map'), options);

                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(lat, lng),
                        map: map,
                        title: 'My workplace',
                        clickable: false,
                        icon: 'img/factory.png'
                    });
                }
  }   
 </script>

Upvotes: 0

Views: 69

Answers (3)

duncan
duncan

Reputation: 31922

The trailing comma on the last item here will cause errors in Internet Explorer:

var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                    };

Should be:

var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };

Upvotes: 0

Dr.Molle
Dr.Molle

Reputation: 117354

GBrowserIsCompatible() is a V2-method, but the rest of your code is V3, you must decide for a single API-version .

Upvotes: 2

akluth
akluth

Reputation: 8583

I do not really know what you want, but

marker.setMap(map);

will show your marker on the map.

With

map.panTo(marker.getPosition())

you can pan your map to the marker.

See https://developers.google.com/maps/documentation/javascript/reference#Marker for more info.

Upvotes: 0

Related Questions