0

I have written a JavaScript to get user geolocation. It gives me latitude and longitude and according to that I have plot user location in map, but when I check that location latitude and longitude in Google map it's different so that it plot me wrong place.

function map()
{
    if (navigator.geolocation) {
        browserSupportFlag = true;
        navigator.geolocation.getCurrentPosition(function (position) {
            initialize(position.coords.latitude,position.coords.longitude);
        }, function () {
            handleNoGeolocation(browserSupportFlag);
        });
    } else {
        browserSupportFlag = false;
        handleNoGeolocation(browserSupportFlag);
}

Please let me know how I can get accurate latitude and longitude by using navigator.geolocation.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Shivkumar
  • 1,903
  • 5
  • 21
  • 32
  • Did you try your code on a real device or on a simulator? – Littm Sep 20 '12 at 08:25
  • How much different is it? Take note that the HTML5 geolocation API isn't fully precise, but it make a [close guess](http://stackoverflow.com/questions/2248404/about-geolocation-in-html-5). – MarcoK Sep 20 '12 at 08:26
  • Maybe you can try alternative solutions, like clientLocation of google API. – theintersect Sep 20 '12 at 08:34
  • Thanks giving me quick reply. @Littm i have not tried it on any real device i have just create a site in which i want to show visited user location on map but i have stuck with above problem. – Shivkumar Sep 20 '12 at 08:46
  • @Marcok i am using HTML5 difference is less means in decimal but it show different. – Shivkumar Sep 20 '12 at 08:50

1 Answers1

2

The Geolocation feature works by using geographical location information available through various sources used depending on the device. This includes satellite data, radio tracking devices, Internet hardware as well as wireless communication equipment. More precisely the system makes use of GPS, RFID, IP address, Wi-Fi and Bluetooth Mac IDs or mobile phone towers and handset IDs. So, if you are trying on browser then that would depend on the browser and its settings. It might use GPS, WLAN AP-based location, IP location, or any other conceivable method of locating itself.

The browser runs on your local machine, so even if you're behind a proxy, it should be able to find your actual IP address (unless security features prevent it from being sent for lookup to a geolocation server). else if you are trying on mobile device with gps turned on then it should provide results with good accuracy as from my past experience with geolocation api

Neji
  • 6,591
  • 5
  • 43
  • 66
  • thanks for reply, so is there any alternate way so i can get more closer Latitude and longitude or some difference is acceptable in this situation. – Shivkumar Sep 20 '12 at 09:25
  • on what device are you trying?? and also i guess there is some accuracy parameter for the purpose to get high accuracy results – Neji Sep 20 '12 at 12:01
  • when i test it on my browser it showed my location 8 kms away from my exact location. It resolves from u r IP address on browser. so It wont be as accurate as you expect when trying to acquire location from your network address. – Neji Sep 21 '12 at 05:25