how do I get geoLocation on a Mac?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how do I get geoLocation on a Mac?

Mark Wieder via use-livecode
How do I get latitude & longitude within a macOS LiveCode script?

———

I know iOS has a way to tell you latitude & longitude. It appears that capability is not available on macOS.

I know that macOS browsers, with WiFi on and connected, can determine lat/long with a javascript command. At this URL:
        https://www.w3schools.com/html/html5_geolocation.asp
I found this example:

<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>


I know that macOS can:
        do <script>  as “javascript”
where <script> is the actual script shown above, not “<script>"

“javascript” is in alternateLanguages() will return true on macOS

Any ideas why the result is "compiler error”?

I am not a javascript person so perhaps I’m screwing up the javascript or not initializing something correctly. And more importantly, how do I get the geolocation of a mac that is on WiFi?

Thanks,
Kee
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: how do I get geoLocation on a Mac?

Mark Wieder via use-livecode
I’m no Javascript expert, so I can’t answer the question about the error, but my best guess is that code needs to be run within a browser.

However, considering that you need to be connected to the internet to access your geolocation on desktop, if you sign up for a free API with https://ipgeolocation.io (for unto 30K non commercial Requests Per Month), then it’s pretty easy to parse the Lat/Long from the returned data with a couple of lines of of simple code, e.g.

   put url(https://api.ipgeolocation.io/ipgeo?apiKey=<myAPIkey>) into tResult -- Replace <myAPIkey> with your unique key

   put item 12 of tResult && item 13 of tResult into tGeoLocation

The result = "latitude":"50.12345" "longitude":"-125.67890”

It’s not quite as accurate as GPS, but it’s close, plus you have the advantage of lots more data returned should you need it and no messing with Javascript.

Paul



> On 1Mar, 2021, at 10:34 AM, kee nethery via use-livecode <[hidden email]> wrote:
>
> How do I get latitude & longitude within a macOS LiveCode script?
>
> ———
>
> I know iOS has a way to tell you latitude & longitude. It appears that capability is not available on macOS.
>
> I know that macOS browsers, with WiFi on and connected, can determine lat/long with a javascript command. At this URL:
> https://www.w3schools.com/html/html5_geolocation.asp
> I found this example:
>
> <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>
>
>
> I know that macOS can:
> do <script>  as “javascript”
> where <script> is the actual script shown above, not “<script>"
>
> “javascript” is in alternateLanguages() will return true on macOS
>
> Any ideas why the result is "compiler error”?
>
> I am not a javascript person so perhaps I’m screwing up the javascript or not initializing something correctly. And more importantly, how do I get the geolocation of a mac that is on WiFi?
>
> Thanks,
> Kee
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: how do I get geoLocation on a Mac?

Mark Wieder via use-livecode
Paul,

This is a great suggestion. I’m trying simulate the iOS geolocation while I develop on macOS. Yours is a great idea.

I have gotten the JavaScript to auto load the lat long when I hit the html page with the JavaScript on my Mac as a file using Safari.

And I’ve gotten the browser widget to load a page from the internet. Could not get browser widget to load from a file on my Mac without enabling an http server on my Mac.

Tried putting the JavaScript page on a remote server and hitting it and that did not work, presumably because the server is not https.

On Wednesday will put the page on an https enabled web site and see if I can get it to load in a browser widget. Will report back.

But if all else fails, the IP to lat long is going to be a good solution. Thanks

Kee Nethery

> On Mar 1, 2021, at 8:35 PM, Paul Hibbert via use-livecode <[hidden email]> wrote:
>
> I’m no Javascript expert, so I can’t answer the question about the error, but my best guess is that code needs to be run within a browser.
>
> However, considering that you need to be connected to the internet to access your geolocation on desktop, if you sign up for a free API with https://ipgeolocation.io (for unto 30K non commercial Requests Per Month), then it’s pretty easy to parse the Lat/Long from the returned data with a couple of lines of of simple code, e.g.
>
>   put url(https://api.ipgeolocation.io/ipgeo?apiKey=<myAPIkey>) into tResult -- Replace <myAPIkey> with your unique key
>
>   put item 12 of tResult && item 13 of tResult into tGeoLocation
>
> The result = "latitude":"50.12345" "longitude":"-125.67890”
>
> It’s not quite as accurate as GPS, but it’s close, plus you have the advantage of lots more data returned should you need it and no messing with Javascript.
>
> Paul
>
>
>
>> On 1Mar, 2021, at 10:34 AM, kee nethery via use-livecode <[hidden email]> wrote:
>>
>> How do I get latitude & longitude within a macOS LiveCode script?
>>
>> ———    
>>
>> I know iOS has a way to tell you latitude & longitude. It appears that capability is not available on macOS.
>>
>> I know that macOS browsers, with WiFi on and connected, can determine lat/long with a javascript command. At this URL:
>>    https://www.w3schools.com/html/html5_geolocation.asp
>> I found this example:
>>
>> <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>
>>
>>
>> I know that macOS can:
>>    do <script>  as “javascript”
>> where <script> is the actual script shown above, not “<script>"
>>
>> “javascript” is in alternateLanguages() will return true on macOS
>>
>> Any ideas why the result is "compiler error”?
>>
>> I am not a javascript person so perhaps I’m screwing up the javascript or not initializing something correctly. And more importantly, how do I get the geolocation of a mac that is on WiFi?
>>
>> Thanks,
>> Kee
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode