how do I get geoLocation on a Mac?
Paul Hibbert
paul at livecode.org
Mon Mar 1 23:34:29 EST 2021
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 <use-livecode at lists.runrev.com> 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
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list