Geolocation with Mobile Data

4

Well, I'm trying to make a project to be used in SmartPhones, specifically in Android, but not developed in Android!

I'm just using HTML5 and CSS, all responsive, and I want a functionality that just worked in Angular (I think)

What I want:

  • I would like to know how I can make mobile phones with Mobile Data able to give them their location

  • or even if you can tell which cell phone is physically closer to a certain designated location (Google Maps or so)
  •   

    Regarding the Code I did not put it because I only have the Front End of   Application .... Regarding location, the idea would even be to use   the GPS of the Mobile Phone ... Since the Web page is made only for   be used on Mobile Phone and not through the Computer! To help   even more .... Imagine that we interconnected the two mobile phones in which   route and a final destination, and that through Location   of both, you can tell which of the Devices is Closer to the   Final Destination!

    I wish I could-without explaining in detail or who does not want me to indicate some type of WebSite / s that can help me!

        
    asked by anonymous 08.02.2017 / 10:56

    1 answer

    5

    So, since you did not give details of your code, I'll post an explanation on HTML5 that I recently read in the W3C documentation on geolocation.

    There are three popular ways to get your position:

    IP Geolocation This is the method used by most Web browsers on computers. Through whois queries and IP location services, it will determine which city or region you are in.

    GPRS triangulation Devices connected to a cellular network and without a GPS, or with the GPS turned off, can determine their position by the triangulation of the next GPRS antennas . It is much more accurate than the IP-based method, it will show where in the neighborhood you are.

    GPS It is the most accurate method. Ideally, the margin of error is only 5 meters. While these are the three most popular ways to solve the problem, they may not be the only ones. Some user agents may use a combination of these methods, or even a new method that might be invented. So the Geolocation API is agnostic over the method used. There is only one way to turn on and off the "high precision mode", which will have different meaning in each user agent.

      

    Let's take an example:

    function getPosition() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(position, erro);
        }
    }
    
    function position(posicao) {
        console.log(posicao.coords.latitude, posicao.coords.longitude);
    }
    
    function erro(positionError) {
        console.log(positionError.code);
        if (positionError.code == 1)
            document.getElementById('msg').innerHtml = 'Usuário bloqueou a localização';
    }
    

    Where postion is a callback function, which will receive a positioning object.

    The getCurrentPosition method receives two other parameters. The first is a function for handling the second error, a configuration object.

    Error will receive an object with details of the error, which will be explained below.

    Running the above code, the browser will display:

    The user can then choose whether or not to share their position with the site. Besides the user being able to say no, a lot can go wrong when it comes to geolocation. To handle this, you can pass the second parameter to getCurrentPosition, in our case the callback erro .

    If something goes wrong, the error function will receive a positionError object, which has the code attribute, which can have one of the following values:

    1- Permission denied

    The user clicked do not share.

    2- Position unavailable

    The user agent is disconnected, GPS satellites could not be reached or some similar error.

    3- Timeout

    Timeout when getting a position. You can set the maximum time when calling getCurrentPosition.

    0- Unknown error

    Something else has prevented the user agent from obtaining a position. Do not treat the user's response as an error, in its error handling function, if you get error code 1, please do not bother the user with error messages. He chose not to share his position with the site. Perhaps the best attitude is to do nothing at the moment.

    Configuration object :

    The third parameter of getCurrentPosition is a configuration object, which can have the following properties:

    enableHighAccuracy

    If true, turn on high precision mode. In a cellular this can instruct the browser, for example, to use GPS instead of GPRS triangulation.

    timeout

    The time in milliseconds that the user agent will wait for the position before triggering a type 3 error.

    maximumAge The time, in milliseconds, that the browser can cache position.

        
    08.02.2017 / 11:23