0

是否可以在使用 jQuery UI Map 的 PhoneGap 应用程序中将当前位置设置为蓝点,并在其周围设置蓝色半径,以实现与 Android 中的原生 Google Maps 应用程序一样的准确性?

如果是这样,我该如何实现

4

1 回答 1

1

通过使用在位置对象内找到的精度值创建一个圆形覆盖来找到解决方法

这是完整的代码(不要忘记添加对这个文件 jquery.ui.map.overlays.js 的引用)

function locSuccess(position) {

//Set the current position as a Google Maps object
var newPoint = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

//Get the marker with the current position
var myPos = $('#map_canvas').gmap('get', 'markers')['myPos'];

//If there is no marker (first time position)
if(!myPos) {
    //Create a new marker
    $('#map_canvas').gmap('addMarker', {
        'id':'myPos',
        'position':newPoint,
        'icon' : 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
    });
    //Create the accuracy circle 
    $('#map_canvas').gmap('addShape', 'Circle', { 'strokeColor': "#86A9F4", 'strokeOpacity': 0.85, 'strokeWeight': 2, 'fillColor': "#C2D0F1", 'fillOpacity': 0.25, 'center': newPoint, 'radius': position.coords.accuracy });
} else {
    //If there is already a marker, update the position
    myPos.setPosition(newPoint); 
    //Update the circle radius and position (I only have 1 Circle, but this code should be improved)
    var circlePos = $('#map_canvas').gmap('get', 'overlays > Circle')[0];
    circlePos.setCenter(newPoint);
    circlePos.setRadius(position.coords.accuracy);
}

    $('#map_canvas').gmap('refresh');
}
于 2013-07-18T17:12:47.433 回答