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?
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?
Share Improve this question asked May 8, 2012 at 13:17 MrFohMrFoh 2,7019 gold badges46 silver badges78 bronze badges 3- This code doesn't contain any errors, are you sure the options object is plete? Also, is there somewhere in your code where you use 'position', that is where the error should be. – Qurben Commented May 8, 2012 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 Commented May 8, 2012 at 13:22 - 2 Yes, you should definitely try to replace $ with document.getElementById that is the way the official examples do it. – Qurben Commented May 8, 2012 at 13:26
1 Answer
Reset to default 6this works :
var mapElem = $("#container").find("#map")[0];
var map = new google.maps.Map(mapElem,mapOptions);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744957232a4603266.html
评论列表(0条)