3
$\begingroup$

The four commands

Here

CloudEvaluate[Here]

CloudEvaluate[FindGeoLocation[]]

CloudEvaluate[$GeoLocation]

all give wildly different results. None of them are correct (some even showing a different country). I assume that CloudEvaluate[Here] gives the location of the Wolfram Cloud server, but why is that different from the other CloudEvaluate commands?

I wish to create a FormPage in the Wolfram cloud where I can enter some data via my phone, including the phone's current location. How do I access the phone's GPS readings from a Wolfram cloud FormPage?

$\endgroup$
1
  • $\begingroup$ I thought that this one is a duplicate 116508 but the fact it is about APIFunction not a FormPage makes it different. $\endgroup$
    – Kuba
    Jan 29, 2019 at 13:51

1 Answer 1

3
$\begingroup$

This seems to work well, it will ask you to give permissions to access gps data and then our JS will initialize "yourPosition" field with coordinates taken from navigator (see: https://www.w3schools.com/html/html5_geolocation.asp)

    CloudDeploy[
      FormPage[{
        EmbeddedHTML @ StringJoin[
          "<script>function initYourPosition( position ) { document.getElementsByName('yourPosition')[0].value = ''+position.coords.latitude+','+position.coords.longitude;}</script>"
        , "<script>navigator.geolocation.getCurrentPosition(initYourPosition)</script>"
        ]
      , "yourPosition"->"GeoCoordinates"
      }
      , GeoGraphics[{ GeoMarker[#], Inset[#2,#]}& @@@ {
          {Here,"\nHere"},
          {$GeoLocation,"$GeoLocation"},
          {FindGeoLocation[],"FindGeoLocation"},
          {FindGeoLocation[$RequesterAddress],"by requester address"},
          {#yourPosition,"navigator.geolocation"}
         },
        GeoRange->Quantity[6,"Kilometers"],
        GeoZoomLevel->Automatic,
        GeoCenter->#yourPosition
      ] &
    ]
    , CreateUUID["temp/"]
    , Permissions -> "Public"
    ]

And the final result after allowing access and submitting:

enter image description here

I found a a Community.wolfram.com post that does even more: Exact GeoPosition from FormFunction but requires a little bigger html+js template.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.