Why does getCurrentposition using google maps with jquery ui map and jquery mobile cause an error?
-
08-06-2021 - |
문제
I am trying to get the current position using the jquery-ui-map (getCurrentPoistion), but iIkeep getting this error:
Uncaught no such method 'getCurrentPosition' for gmap widget instance
This is my code:
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 } );
});
How can I fix this?
해결책
As Andrew Leach mentioned, the getCurrentPosition is an extension of the plugin. Most likely you haven't included jquery-ui-map-extensions.js
제휴하지 않습니다 StackOverflow