0

i'm using google map to get user latitude and longitude. just i want check if a latitude and longitude is either inside or outside the area (from central 5 kilometers)

my java script code is:

var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}

i get good function but in android , I want something similar but in java script:

    float[] results = new float[1];
Location.distanceBetween(centerLatitude, centerLongitude, testLatitude, testLongitude, results);
float distanceInMeters = results[0];
boolean isWithin10km = distanceInMeters < 10000;
Ayman
  • 23
  • 7
  • You need to calculate the direct distance between two sets of lat/lng coordinates you need to use the [Inverse Haversine](https://en.wikipedia.org/wiki/Haversine_formula) formula. See the duplicate for more information – Rory McCrossan Mar 09 '20 at 08:50
  • thanks i got the solution by Using the Haversine Formula in Javascript – Ayman Mar 09 '20 at 11:35

0 Answers0