Wrong location API Google HTML

2

Hello, I'm trying to capture my location from the Google API / with the features of the new HTML5.

But my latitude and longitude always gives this one that is incorrect, either on the computer or mobile:

latitude: -23.550519899999998
longitude: -46.633309399999995

On the cell phone I have already enabled the location via GPS but still it still incorrect, what can it be?

Here is the code I'm using:

<!DOCTYPE html>
<html>
    <body>
        <p id="demo">Aceite para receber sua localização em Latitude e Longitude</p>
        <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script><script>varapiGeolocationSuccess=function(position){alert("API geolocation success!\n\nlat = " + position.coords.latitude + "\nlng = " + position.coords.longitude);
            };

            var tryAPIGeolocation = function() {
                $.post( "https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDCa1LUe1vOczX1hO_iGYgyo8p_jYuGOPU", function(success) {
                    apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});
              })
              .fail(function(err) {
                alert("API Geolocation error! \n\n"+err);
              });
            };

            var browserGeolocationSuccess = function(position) {
                alert("Browser geolocation success!\n\nlat = " + position.coords.latitude + "\nlng = " + position.coords.longitude);
            };

            var browserGeolocationFail = function(error) {
              switch (error.code) {
                case error.TIMEOUT:
                  alert("Browser geolocation error !\n\nTimeout.");
                  break;
                case error.PERMISSION_DENIED:
                  if(error.message.indexOf("Only secure origins are allowed") == 0) {
                    tryAPIGeolocation();
                  }
                  break;
                case error.POSITION_UNAVAILABLE:
                  alert("Browser geolocation error !\n\nPosition unavailable.");
                  break;
              }
            };

            var tryGeolocation = function() {
              if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(
                    browserGeolocationSuccess,
                  browserGeolocationFail,
                  {maximumAge: 50000, timeout: 20000, enableHighAccuracy: true});
              }
            };

            tryGeolocation();
        </script>
        <!--<script>
            $(function(){
                getLocation();
            });
            var x = $("#demo");
            function getLocation(){
                if(navigator.geolocation){
                    navigator.geolocation.getCurrentPosition(showPosition);
                } else {
                    x.text("O seu navegador não suporta Geolocalização.");
                }
            }
            function showPosition(position){
                //console.log("Latitude: " + position.coords.latitude +" Longitude: " + position.coords.longitude);
                x.text("Latitude: " + position.coords.latitude +" Longitude: " + position.coords.longitude)
            }
        </script>-->
    </body>
</html>

The following is the code response:

    
asked by anonymous 26.05.2017 / 16:13

0 answers