Obtain current geolocation data using VBA

Ok that's normal for a desktop PC and some laptops which may not have its own geolocation sensor. If so, it uses the default location provided by your ISP so my code can't get your correct location. On some laptops and all tablets, the sensor is available and it will work.

I've not checked those coordinates but if you use BT as I do, the location will be somewhere around Haverfordwest. That's why you'll see a lot of ads mentioning that location on MSN etc

If you are happy to do so, you can set a default location in Windows which the code will then pickup.
 
Last edited:
No, it is on a common a few miles from me.
Please see pics.
I've set default location as SA5 4LH, but it still shows same coordinates.

I'll try those other instructions when I get home tonight.
 

Attachments

  • Coord1.jpg
    Coord1.jpg
    88.4 KB · Views: 219
  • Coord2.jpg
    Coord2.jpg
    54.8 KB · Views: 204
Colin,
Home computer is a laptop.
Copied files to your UKPAF folder.
IE11 opens and finds my real location.
When I come back to the DB I get the error70 display?

Second attempt, IE closed itself, and the DB got -4.033115 long, but lat was still at 100.
Exited and reopened DB several times, and IE11 is closing almost as soon as I confirm Allow Once, with just the long value being returned.

Next amended the map via Chrome
Tried the DB again, but not even getting time to click Allow Once and IE closes. Tried again and when I can get to click Allow Once the browser closes again only passing back Long value.
I am not sure my editing the html file is working. I added something to the comments, and saved as a single web page. Yet when I go back into it, the edit is gone. I am just using Ctrl +S to save ?
Even tried adding another comment line and that is also gone when reopened.:banghead:

I also added the extra err check for 438 and now 70 as well, but no change, still only for the long value.

I don't have time at present to walk through the code, sorry. Might get time on the weekend?

Edit: Just copied the modified DB back to the Temp folder (where I ran it from last night). First attempt never got chance to click Allow Once, second attempt, just the Long value returned again.

HTH
 

Attachments

  • error70.PNG
    error70.PNG
    10.2 KB · Views: 197
Gasman
I had this working successfully on 3 computers at home - all running Win10 - desktop / laptop / tablet

My desktop PC was updated to the latest Windows 10 version (Spring Creators Edition) this afternoon.
I've just tried the app & it no longer works for me either! Basically same issues as I reported in post 12

From the app, the IE window opens with Allow Blocked Content button.
After clicking that & Allow Once I get the Geolocation Service failed message in IE and the Automation Error message in the DB

So I tried opening the HTML file direct in different browsers
All ask for permission to use my location (as they are required to do)
Firefox - gets my ISP location (Haverfordwest) rather than my home location & is VERY slow
Chrome - same as for Firefox but fast
Edge - gets my home location & also fast
IE - blocked content message first then geolocation failed message

So I never thought I'd say it but in this context Edge works best

As for IE, I'm going to try & identify what setting has changed - the key to success is stopping that Allow Blocked Content message appearing.

Suggest you have a look at the IE Internet Options & check the Privacy section. Make sure you haven't ticked the don't allow sites to ask for location

I'm going to going to try other ways of getting the desired result starting with using an Access web browser control (though that's also IE based)

I suggest that we continue this discussion by email as necessary until either of us identifies the issue. Once that is the case, then publish the findings here on the forum
 
Last edited:
FURTHER UPDATE:
For anyone else having issues getting this to work, here is one more thing you could try.
Using any browser other than IE e.g. (Edge / Chrome / Firefox), open this page on the W3Schools site: https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation
Click the Try It button – your coordinates should be displayed (though on a desktop you may get your ISP server location instead

Now repeat but using IE.
On my newly updated desktop PC absolutely nothing happens.
That’s why it won’t work in my app either
On my laptop / tablet it still works using IE

I've since spent a couple of hours changing IE settings & related registry settings. My efforts to get this working again on my newly updated PC have been fruitless. I even removed & reinstalled IE11. No joy.


AND A FURTHER UPDATE:
My laptop was also updated to Windows 10 version 1803 overnight.
I can confirm that Windows geolocation service now also fails using IE on that device.
It worked beforehand.
The update to version 1803 has broken my code! :banghead: :mad:
 
Last edited:
UPDATE:
I've just run a remote connection session with MS support after reporting the 'IE geolocation service failed error' as a bug caused by the Win10 v1803 update.

They have confirmed this to be the case & have forwarded it for action (I won't hold my breath). At their request, I've also raised it as a problem in the Feedback Hub

In the meantime, I have reverted to version 1709 and the code works perfectly for me again
So does the W3Schools link mentioned in the last post
 
Excellent run down and identification of issue - hard to get things working when they are bugged!!!

I would imagine even Microsoft will want to fix that.
 
A further update:
2 days ago, I started getting 'Allow Blocked Content' messages when the HTML file was opened in IE. This prevented the code working ... AGAIN!

After wasting a lot of time on this, it transpires the message was caused by the poorly documented 'Mark of the Web' issue - local HTML files containing ActiveX content are now routinely blocked.
To fix, the HTML file needs one extra line shown in RED followed by a blank line like this
Code:
<!DOCTYPE html>
[COLOR="Red"]<!-- saved from url=(0014)about:internet -->[/COLOR]

<html>

The file also needs to be encoded as UTF-8 format
My guess is I had saved as ANSI format and triggered the behaviour
See attached for FIXED version.

Unfortunately the Win 10 v1803 issue which I reported to MS isn't fixed doing this - hopefully MS will fix that soon.
It seems the latest Win 10 update has caused a lot of issues
 

Attachments

Yes, you can extract current location data (latitude/longitude) using VBA by utilizing external APIs or libraries that provide access to GPS or geolocation information, and then parsing the returned data within your VBA script. It's not a built-in feature in VBA, so you'll need to integrate with external resources for this functionality
 

Users who are viewing this thread

Back
Top Bottom