How to Get Geographic Address without Permission

I wanted to extend on a tip that was provided previously. I was able to incorporate some functionality that I think really helps out when attempting to get a users geographic address.

Something I’ve had difficulty with was permissions. In the past I had some weird behaviors and had to give up on a function that required requesting the users address. Once they blocked the request I always got bug errors in the debugger.

I found on the forum a tip by @romanmg that got me started. I highly recommend checking it out as I won’t go over what she covered very well.

Tip: How to Get a User's Location Details Using Their IP Address

After watching her video I needed to find a way to get the users geographic address without using the search box to get a geographic place and a more accurate location from the coordinates.

I found a thread that @NigelG mentioned using an expression to extract the coordinates and to use the built in calculate coordinates to address function.

I reached out to Nigel for the expression and he was kind enough to provide them.

From this I put together a workflow action in my reusable header element to get the current users geographic address.

I needed a popup element to store a few inputs to keep the coordinates as numbers as well as to calculate the geographic address.

Screen Shot 2020-04-21 at 9.20.48 PM

As bubble will track users who are not signed up or logged into the app, you can still keep the users information for return visits.

I had been avoiding implementing a lot of time related functions as well as search based on distance, but now I have an easy way to use the users location to return search results using distance.

Thanks to Gaby and Nigel.

7 Likes

One issue with this method is that it is not always accurate. There are two types of IP address…IPv4 and IPv6 and the plugin that bubble created uses a service that doesn’t regularly provide the same IP address type.

My first tests I got accurate results. With subsequent tests the following day the address was a couple hundred kilometers away. This was explained by bubble support to be caused by a return of the IPv6 instead of IPv4. Apparently it is the provided the plugin uses and not in bubble control.

I am not sure why the bubble built in “current geographic position” always returns accurate results, I’d assume they use the same provider for IP address details, but maybe not. The problem with “current geographic position” is that it asks for permission and once a user denies, it never asks them again and just provides a error message in the debugger tool that the user has denied geolocation services.

I had tried without success to get feedback from the bubble community on their experiences with this issue.

3 Likes

Wow - I finally managed to get this working. Thanks @boston85719 for documenting what you did, and @NigelG for sharing the Regex.

Just for anyone else reading this, I had to do a couple of things a bit differently, no idea why but maybe someone has some ideas.

First, I wanted to save the values to a State. When I extracted the coordinates, it would only extract them a a List of Texts. So I had to use Convert to a Number, and then I had to have my Latitute and Longitude Number States set up as Lists.

Then when I used the Latitude and Longitude in CalculateCoordtoAddress I had to use :FirstItem for each of them. Probably something I did wrong, but at least it works now in the end. Finally I can order my RG by an Item’s distance from the User, even when the are not logged in!

This seems an awfully over-complicated thing to have to do though! Would it not be possible for the IP Geo Plugin to just determine a Geographic Address in the first place?

1 Like

Sure, just give it an IP address

Bear in mind that IP Address Geo can be miles away from actual GPS/Mobile location.

In my case 50 miles.

Not so good for distance calculation or navigation :slight_smile:

1 Like