0

I used navigator.geolocation.getCurrentPosition() for geo location and i got lat long. But when i try to access Brazil country lat long using this method can't give me lat long.

Suggest me how to get lat long values in Brazil country.

Code:

<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script> 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;
    }
   </script> </body> </html>
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • This is hard to understand in its current form. Can you show some code and the results you're getting? – Pekka Feb 22 '16 at 09:42
  • Click the button to get your coordinates.

    – Akash Phadtare Feb 22 '16 at 10:18
  • Can you edit the code into your question, and tell us what results you are getting? – Pekka Feb 22 '16 at 10:22
  • i'm not getting any error message.if i try to access lat long in brazil country i'm not getting any lat long but this code is working for all others country. – Akash Phadtare Feb 22 '16 at 13:41
  • Well, what *are* you getting then? – Pekka Feb 22 '16 at 14:15
  • first prompt display when i'm clicking Allow Location then not getting any lat and long – Akash Phadtare Feb 22 '16 at 14:20
  • So you are in Brazil and it's not working on your machine? Is the machine capable of geolocation (e.g. with a built-in GPS)? – Pekka Feb 22 '16 at 14:39
  • yes.my machine capable for geolocation – Akash Phadtare Feb 22 '16 at 15:17
  • And when you are outside Brazil, it works? Have you tried a Geolocation example like this one: http://www.w3schools.com/html/html5_geolocation.asp and confirmed whether it works? – Pekka Feb 22 '16 at 15:18
  • yes. w3schools.com/html/html5_geolocation.asp link not work in brazil means not showing lat long. – Akash Phadtare Feb 22 '16 at 15:20
  • Then it's your computer, or its connection - for example, it may not have anything to do geolocation with, like geographical information from the Wi-Fi router. – Pekka Feb 22 '16 at 15:21
  • yes.in brazil i cant find my browser lat long – Akash Phadtare Feb 22 '16 at 15:24
  • please give me a solution. – Akash Phadtare Feb 22 '16 at 15:24
  • What for? I suppose you could somehow set up your router with geographical info, but I don't know how. It depends on many different things, the type of computer, the type of router, etc. - and it'd fix things *for your computer only*. If you need to have a location for development purposes, you can manually set one - see http://www.labnol.org/internet/geo-location/27878/ – Pekka Feb 22 '16 at 15:27

0 Answers0