我使用以下代码通过使用jquery,jqueryui-map和google maps API向地图添加形状
$('#map_canvas').gmap('getCurrentPosition', function(position, status) {
if ( status === 'OK' ) {
var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
$('#map_canvas').gmap('addMarker', {'position': clientPosition, 'bounds': false});
$("#map_canvas").gmap("option", "center", clientPosition);
$('#map_canvas').gmap('option', 'zoom', 14);
$('#map_canvas').gmap('addShape', 'Circle', {
'strokeColor': "#008595",
'strokeOpacity': 0.8,
'strokeWeight': 2,
'fillColor': "#008595",
'fillOpacity': 0.35,
'center': clientPosition,
'radius': 50,
'clickable': false });
}
});
Run Code Online (Sandbox Code Playgroud)
我还尝试在$('#map_canvas')上调用.addShape方法.但我只得到以下错误:
Uncaught TypeError: Cannot call method 'apply' of undefined jquery.ui.map.js:46
$.a.$.fn.(anonymous function) jquery.ui.map.js:46
e.extend.each jquery.min.js:2
e.fn.e.each jquery.min.js:2
$.a.$.fn.(anonymous function) jquery.ui.map.js:40
(anonymous function) :8080:397
$.extend.getCurrentPosition
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-geolocation.html上的示例由于某种原因而起作用.我只是无法弄清楚实际的差异.也许我现在要失明了;) …
我有以下代码工作正常,但我无法添加缩放级别.根据它应该使用的文档,'option', 'zoom', 7但这给出了一个错误:"$("#map_canvas").gmap("option", "zoom", 7).bind is not a function"
工作代码,无法缩放,编辑.缩放始终为1.
$("#map_trigger").click(function(){
var prop_id = $("#map_canvas").attr("rel");
$('#map_canvas').gmap({'zoom':6}).bind('init', function(evt, map) {
$.getJSON( basepath+'properties/get_gps_coords/'+prop_id, function(data) {
$.each( data.markers, function(i, m) {
lat = m.latitude;
longitude = m.longitude;
$('#map_canvas').gmap(
'addMarker', { 'position': new google.maps.LatLng(lat, m.longitude), 'bounds':true }
);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
如何为此代码段添加缩放级别?
使用jquery-ui-map.
我正在通过JSON加载数据,带有一些标记和地图新中心的纬度/经度(位置查找器应用程序).
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});
Run Code Online (Sandbox Code Playgroud)
所有三个中心呼叫都失败了:
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
Run Code Online (Sandbox Code Playgroud)
这里的规范方式是什么?
有人可以解释google jquery.ui.map插件中的以下代码片段(jQuery.fn[name])的含义:
jQuery.each(('click mousedown rightclick dblclick mouseover mouseout drag dragend').split(' '), function(i, name) {
jQuery.fn[name] = function(a, b) {
return this.addEventListener(name, a, b);
};
});
Run Code Online (Sandbox Code Playgroud)
以及我们如何将回调函数绑定到地图对象上的click事件,我尝试了以下但是event没有latLng属性:
$('#map_canvas').gmap().click(function(event) {
alert(event.latLng);
});
Run Code Online (Sandbox Code Playgroud)
提前致谢.
jquery callback addeventlistener google-maps-api-3 jquery-ui-map