使用 jquery-ui-map。
我正在通过 JSON 加载数据,其中包含一些标记和 map 的新中心(位置查找器应用程序)。
var origin = new google.maps.LatLng(data.origin.latitude, data.origin.longitude)
// adding the marker for the new origin works
$('#map_canvas').gmap('addMarker', {'position': origin});
// does not work
$('#map_canvas').gmap('center', '49, 7');
// does not work
$('#map_canvas').gmap('center', origin);
// does not work
$('#map_canvas').gmap('center', {'position': origin});
三个中心调用全部失败:
Uncaught TypeError: Cannot call method 'apply' of undefined
$.a.$.fn.(anonymous function)jquery.ui.map.js:46
b.extend.eachjquery.js:35
b.fn.b.eachjquery.js:28
$.a.$.fn.(anonymous function)jquery.ui.map.js:40
(anonymous function)@@geosearch:477
c.extend.handleSuccessjquery.js:144
c.extend.ajax.w.onreadystatechange
这里的规范方式是什么?
最佳答案
使用这个:
$('#map_canvas').gmap('get','map').setOptions({'center':origin});
另见此链接: http://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions
关于javascript - 如何使用 jquery-ui-map 重新居中 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9563314/