Подтвердить что ты не робот

Как лучше отображать точность геолокации HTML5 на карте google

Я бы хотел:

  • собрать широту, долготу и точность пользователя, использующего HTML5
  • отобразить, что на карте google как точка
  • измените размер точки и действительно масштаб карты, чтобы отразить точность положения.

Это должно быть возможно, но я еще не видел, чтобы кто-то реализовал это.

4b9b3361

Ответ 1

Должно быть возможно. В соответствии с этой статьей объект позиции HTML5 возвращает свойство точности в метрах.

Карта google api имеет возможность рисовать круги с учетом центральной точки (lat, lng) и радиуса в метрах.

Я думаю что-то вроде этого:

var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;

var centerPosition = new google.maps.LatLng(latitude, longitude);

var marker = new google.maps.Marker({
   position: centerPosition,
   map: //your map,
   icon: //the dot icon
});

var circle = new google.maps.Circle({
    center: centerPosition,
    radius: accuracy,
    map: //your map,
    fillColor: //color,
    fillOpacity: //opacity from 0.0 to 1.0,
    strokeColor: //stroke color,
    strokeOpacity: //opacity from 0.0 to 1.0
});

//set the zoom level to the circle size
map.fitBounds(circle.getBounds());

Ответ 2

    var circle;

    function initialize() {
       // Create the map.
        var mapOptions = {
            zoom: 4,
            center: new google.maps.LatLng(37.09024, -95.712891),
            mapTypeId: google.maps.MapTypeId.TERRAIN
        };

        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        // Construct the circle for each value in citymap.
        // Note: We scale the area of the circle based on the population.
        var populationOptions = {
            strokeColor: '#FF0000',
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: '#FF0000',
            fillOpacity: 0.35,
            map: map,
            center: citymap[city].center,
            radius: Math.sqrt(citymap[city].population) * 100
        };
        // Add the circle for this city to the map.
        circle = new google.maps.Circle(populationOptions);
    }

Источник: Документация Google