2

Am trying to display a location on a map using goolge maps, with the function below

function show_map(options) {
            var mapOptions = {
                center: new google.maps.LatLng(options.lat, options.lng),
                zoom: 12,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

              var map = new google.maps.Map($("#map-canvas"),mapOptions);
        }

and i get this error "Cannot set property 'position' of undefined". What might the problem be?

MrFoh
  • 2,693
  • 9
  • 42
  • 77
  • This code doesn't contain any errors, are you sure the options object is complete? Also, is there somewhere in your code where you use 'position', that is where the error should be. – Qurben May 08 '12 at 13:22
  • 8
    One thing is that you probably don't want to pass a jQuery object `$("#map-canvas")` as a parameter, do you? That would either be the element itself `$("#map-canvas")[0]`, or just the name `"map-canvas"` (I don't which one, I don't work with google maps). – Imp May 08 '12 at 13:22
  • 2
    Yes, you should definitely try to replace $ with document.getElementById that is the way the official examples do it. – Qurben May 08 '12 at 13:26

1 Answers1

6

this works :

var mapElem = $("#container").find("#map")[0];
var map = new google.maps.Map(mapElem,mapOptions);
Patrice
  • 1,404
  • 1
  • 14
  • 27