我正在尝试使用 jquery-ui-map (getCurrentPoistion) 获取当前位置,但 iIkeep 收到此错误:
未捕获 gmap 小部件实例的此类方法“getCurrentPosition”
这是我的代码:
var defaultLoc = new google.maps.LatLng(-0.9516469154747268, 30.269393920898438);
$('#map_canvas_dir').gmap({ 'center': defaultLoc, 'zoom':10});
$('#submit').click( function() {
$('#map_canvas_dir').gmap('getCurrentPosition', function(status, pos) {
if (status === "OK") {
var latLng = new google.maps.LatLng(pos.coords.latitude,
pos.coords.longitude);
$('#map_canvas_dir').gmap('option', 'center', latLng);
addNewMarker( latLng, 'green' );
}
else {
console.log('shit! it failed again');
}
}, { timeout: 4000, enableHighAccuracy: true } );
});
我怎样才能解决这个问题?