cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Geoposition from web browser

jserrano
1-Newbie

Geoposition from web browser

I am trying to get currents geoposition from my web browser to my thingworxs app with no succes. Do you guys know a way to get this data?

Kingd regards and happy holidays!

3 REPLIES 3
tcoufal
12-Amethyst
(To:jserrano)

There might be more possible ways how to get it done, but this one worked for me.

IPInfoDB | Free IP Address Geolocation Tools

It is an IP based geolocation database with REST API laying on top of that. Keep in mind that precision comes from your internet provider. Version which is free provides a city-level precision and limited REST calls per day. But I was getting quite good results with even this one. +-500m if I remember correctly.

¨Tom 

BryanK
14-Alexandrite
(To:tcoufal)

Hi,

I'm also interested in getting this but i dont seem to be getting any good results. 

I was hoping to do something that like this.

https://www.w3schools.com/Html/html5_geolocation.asp

but without the html. 

something like this.

 

var x = me.location;
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x = "Latitude: " + position.coords.latitude + 
    "Longitude: " + position.coords.longitude; 
}

 

Is this possible? My jsp skills are not very good. 

 

Thanks

Bryan

BryanK
14-Alexandrite
(To:jserrano)

So I'm still hacking away at this. 

https://w3c.github.io/geolocation-api/

I thought as a start I would create a service that just does this.

EXAMPLE 1: Example of a "one-shot" position request
function showMap(position) {
  // Show a map centered at (position.coords.latitude, position.coords.longitude).
}

// One-shot position request.
navigator.geolocation.getCurrentPosition(showMap);

The first error that I get is that navigator is unknown or something.

back to the drawing board I suppose. 

 

here is an example of what I want to do with a service 

 

<!DOCTYPE html>
<html>
  <head>

    <script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
    <script>
        jQuery(window).ready(function(){
            jQuery("#btnInit").click(initiate_geolocation);
        });

        function initiate_geolocation() {
            navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
        }

        function handle_errors(error)
        {
            switch(error.code)
            {
                case error.PERMISSION_DENIED: alert("user did not share geolocation data");
                break;

                case error.POSITION_UNAVAILABLE: alert("could not detect current position");
                break;

                case error.TIMEOUT: alert("retrieving position timed out");
                break;

                default: alert("unknown error");
                break;
            }
        }

        function handle_geolocation_query(position){
            alert('Lat: ' + position.coords.latitude +
                  ' Lon: ' + position.coords.longitude);
        }
    </script>
  </head>
  <body>
    <div>
      <button id="btnInit" >Find my location</button>
    </div>
  </body>
</html>
Top Tags