为什么getCurrentposition使用谷歌地图和jquery ui map和jquery mobile会导致错误



我正在尝试使用 jquery-ui-map (getCurrentPoistion) 获取当前位置,但 iI不断收到此错误:

未捕获没有这样的方法 'getCurrentPosition' 对于 gmap 小部件实例

这是我的代码:

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 } );
});

我该如何解决这个问题?

正如Andrew Leach所提到的,getCurrentPosition是插件的扩展。很可能你没有包含jquery-ui-map-extensions.js

最新更新