Geolocation API (solved)

Is there a reason why Geolocation API isn’t working in Gdevelop?

When I checked if geolocation was in navigation it returned true.
But I haven’t been able to get the method navigator.geolocation.getCurrentPosition to return any useful coordinates.

I really don’t want to use Construct, so I’m hoping that I can get this to work.

1 Like

I got it to work!
It only works on the exported version. :exploding_head:

3 Likes

hi,
can you explain how it works or when I can read about it??
Thanks

1 Like

Cool, you know Js can be powerful in GD i use it too :slight_smile:
What use want to do with Geolocation, a Niantic game like ?

hello Nicanor
How can i show the source code? I didn’t know it is possible

Thanks,
J

I’m building a GPS scavenger hunt and have been struggling to get this part of the project working.

I used the GeoNavigation API which is built into browsers. You can read about it here.

I shared a picture of my code. The top one is checking if geonavigation exsists in navigation. And it returns true. After this test I was pretty confident I could get it to work. The final one works on mobile because I added buttons instead of key presses to update the location and then a second button to print the text to screen. I have a scene variable called Scvar and a text object in the scene.

When the A button is pressed the geonav code gets the device’s location and stores it in the scene variable Scvar

I press Q to update the text object with the value held in Scvar.

It returned an error while testing it directly from Gdevelop but when I exported it to a local folder and opened it locallly it worked. It takes a few seconds to get the location. You can get a feel for it when you try the JavaScript in a browser on the link above.

I’ve been trying to get something working for months so I’m very happy it finally worked. I literally jumped up and cheered. I’m new to JavaScript and Gfevelop so it’s not perfect or elegant but it works!!

3 Likes

Amazing bro I love your work i remember my first time with Vuforia in Unity it was so awesome feeling never crossed my mind the AR with GDevelop maybe we can establish it in GDevelop and make AR games possible.

would you mind sharing the json file??