javascript - Google maps request returning "Cannot set property 'position' of undefined" - Sta

Am trying to display a location on a map using goolge maps, with the function belowfunction show_map(op

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
Add a ment  | 

1 Answer 1

Reset to default 6

this works :

var mapElem = $("#container").find("#map")[0];
var map = new google.maps.Map(mapElem,mapOptions);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744957232a4603266.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信