marcadores icon google example content aƱadir javascript html5 google-maps-api-3 geolocation

javascript - icon - Google Maps v3: radio del mapa visible en millas



google maps markers icons (1)

// Watches for map bounds change - if so - set radius and refresh data Start function setproximityfrommap() { // http://stackoverflow.com/questions/3525670/radius-of-viewable-region-in-google-maps-v3 // Get Gmap radius / proximity start // First, determine the map bounds var bounds = map.getBounds(); // Then the points var swPoint = bounds.getSouthWest(); var nePoint = bounds.getNorthEast(); // Now, each individual coordinate var swLat = swPoint.lat(); var swLng = swPoint.lng(); var neLat = nePoint.lat(); var neLng = nePoint.lng(); var proximitymeter = google.maps.geometry.spherical.computeDistanceBetween(swPoint, nePoint); var proximitymiles = proximitymeter * 0.000621371192; proxmity = proximitymiles; console.log("Proxmity " + proximitymiles + " miles"); }

¿Cómo puedo encontrar la proximidad del área visible de mi mapa?

Todo esto funciona y es una publicación para ayudar a otros que pueden estar buscando.

Este código mira tu Google Map v3 y muestra por var proximidad el radio en millas de tu vista de mapa actual.

Asegúrate de que en tu HTML tienes

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>

como libraries = geometry lo habilita.

// Get Gmap radius / proximity start var bounds = new google.maps.LatLngBounds(); var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); var proximitymeter = google.maps.geometry.spherical.computeDistanceBetween (sw, ne); var proximitymiles = proximitymeter * 0.000621371192; alert(" " + proximitymiles + " Miles Proximity"); var proxmity = proximitymiles; // Get Gmap radius / proximity End

Espero que esto ayude a alguien.

Una edición adicional (no probada) que permite la rotación de la pantalla sigue:

// Get Gmap radius / proximity start var bounds = new google.maps.LatLngBounds(); var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); var se = bounds.getSouthEast(); var nw = bounds.getNorthWest(); var proximitymeterswne = google.maps.geometry.spherical.computeDistanceBetween (sw, ne); var proximitymetersenw = google.maps.geometry.spherical.computeDistanceBetween (se, nw); if (proximitymeterswne > proximitymetersenw) {proximitymeterswne = proximitymiles} else {if (proximitymetersenw > proximitymeterswne) {proximitymetersenw = proximitymiles};}; var proximitymiles = proximitymeter * 0.000621371192; alert(" " + proximitymiles + " Miles Proximity"); var proxmity = proximitymiles; // Get Gmap radius / proximity End

Otro EDIT

// Watches for map bounds change - if so - set radius and refresh data Start function setproximityfrommap() { // http://stackoverflow.com/questions/3525670/radius-of-viewable-region-in-google-maps-v3 // Get Gmap radius / proximity start var bounds = new google.maps.LatLngBounds(); // bounds = map.LatLngBounds(); //center = new google.maps.LatLng(); ne = bounds.getNorthEast(); center = map.getCenter(); //var center = map.LatLngBounds.getCenter(); //var ne = map.LatLngBounds.getNorthEast(); // r = radius of the earth in statute miles var r = 3963.0; // Convert lat or lng from decimal degrees into radians (divide by 57.2958) var lat1 = center.lat() / 57.2958; var lon1 = center.lng() / 57.2958; var lat2 = ne.lat() / 57.2958; var lon2 = ne.lng() / 57.2958; // distance = circle radius from center to Northeast corner of bounds proximity = r * Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)); $(''#proximity'').val(proximity); // Get Gmap radius / proximity End };

Puse el código editado en la primera publicación.

Terran