locked
Cannot add reference to geolocation.dll RRS feed

  • Question

  • I am using Visual Studio Express 2012 for desktop undr windows 10.  I am trying to add a reference to geolocation.dll.

    I get the following message:

    A reference to 'C\Windows\System32\Geolocation.dll' could not be added.  Please make sure that the file is accessable, and that it is a valid assembly or COM component.

    Help is appreciated.


    Ron Chandler


    Tuesday, December 22, 2015 3:08 PM

Answers

  • Right,

    I was just changing that: Essentially you had the event subscribing to the wrong one.

    *****

    What do you want to do from here? Do you want me to do something with a map from Bing?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:53 PM
  • Solved it:

    Imports GeoInfo

    Public Class LocationData

        Private WithEvents myGeoData As Geo.GeoData
        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            myGeoData = New Geo.GeoData
            myGeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

        Private Sub geoData_OperationComplete(sender As Object, _
                                  e As Geo.GeoData.OperationCompleteEventArgs) _
                                  Handles myGeoData.OperationComplete
            If e.OperationException IsNot Nothing Then
                MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _
                                              vbCrLf, e.OperationException.Message), _
                                              "Program Error", MessageBoxButtons.OK, _
                                              MessageBoxIcon.Warning)
            Else
                TextBoxInternetCity.Text = e.Locality
                TextBoxInternetZip.Text = e.PostalCode
                TextBoxInternetLat.Text = e.Latitude.ToString("f6")
                TextBoxInternetLon.Text = e.Longitude.ToString("f6")
            End If
        End Sub


    Ron Chandler

    Thursday, December 24, 2015 3:49 PM

All replies

  • I am using Visual Studio Express 2012 for desktop undr windows 10.  I am trying to add a reference to geolocation.dll.

    I get the following message:

    A reference to 'C\Windows\System32\Geolocaion.dll' could not be added.  Please make sure that the file is accessable, and that it is a valid assembly or COM component.

    It might be just a typo in your post, but the error message refers to "Geolocaion.dll" while the correct filename is "Geolocation.dll".
    • Edited by Blackwood Tuesday, December 22, 2015 3:20 PM
    • Proposed as answer by Frank L. Smith Tuesday, December 22, 2015 3:23 PM
    Tuesday, December 22, 2015 3:19 PM
  • It's just a typo

    Ron Chandler

    Tuesday, December 22, 2015 9:01 PM
  • Cannot see anything useful there.  Still cannot add the reference, even after it showed up when I browsed the references.  It's in c\Windows\System 32, but can not be added!

    Ron Chandler

    Tuesday, December 22, 2015 9:05 PM
  • Cannot see anything useful there.  Still cannot add the reference, even after it showed up when I browsed the references.  It's in c\Windows\System 32, but can not be added!

    Ron Chandler

    I tried adding it and see that you are correct, Visual Studio will not allow it to be added as a reference. You can't add a reference to just any DLL (I believe it needs to be either .Net or COM DLL). It seems that Geolocation.dll is not one of the allowed types.
    • Proposed as answer by Naomi N Friday, December 25, 2015 1:04 AM
    Tuesday, December 22, 2015 9:23 PM
  • Tried again, no luck:  Error Messages

    Net: The file 'C\Windows\System32\Geolocation.dll' is not valid

    COM Components: The type library 'C\Windows\System32\Geolocation.tlb' could not be loaded

    This doesn't seem right.

    Please respond


    Ron Chandler


    Tuesday, December 22, 2015 9:56 PM
  • Tried again, no luck:  Error Messages

    Net: The file 'C\Windows\System32\Geolocation.dll' is not valid

    COM Components: The type library 'C\Windows\System32\Geolocation.tlb' could not be loaded

    This doesn't seem right.

    I don't know anything about that library. What makes you think that it is a .Net or COM library?

    Tuesday, December 22, 2015 10:34 PM
  • I don't know if they are .net or COM items, but every browse in Visual Studio Express 2012 that starts with a search on "geo" turns up the Geolocation files listed above.  I didn't just try these out of thin air - they seem to be components that are compatible with the project, otherwise why do they show up?


    Ron Chandler

    Tuesday, December 22, 2015 10:52 PM
  • I don't know if they are .net or COM items, but every browse in Visual Studio Express 2012 that starts with a search on "geo" turns up the Geolocation files listed above.  I didn't just try these out of thin air - they seem to be components that are compatible with the project, otherwise why do they show up?


    Ron Chandler

    I think you are just searching \Windows\System32\ for anything beginning with "Geo". DLLs in that folder do not have to be .Net or COM libraries. It might be a good idea to go back to whatever suggested that you use a library called Geolocation and look for instructions on where to find that library, or alternatively how to use it.
    Tuesday, December 22, 2015 11:10 PM
  • Please read carefully:  I am using Visual Studio Express 2012 tools.  Under choose toolbox items, browse Net framework components and COM components.  I am not  searching \Windows\System32\ for anything beginning with "Geo".

    Ron Chandler

    Tuesday, December 22, 2015 11:20 PM
  • Please read carefully:  I am using Visual Studio Express 2012 tools.  Under choose toolbox items, browse Net framework components and COM components.  I am not  searching \Windows\System32\ for anything beginning with "Geo".

    Ron Chandler

    Why are you trying to add something to your toolbox?

    At any rate, try to add a reference to it. Right-click on the project name in Solution Explorer, select "Add Reference" and then look in the .Net tab.

    Is it in there?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Tuesday, December 22, 2015 11:26 PM
  • Please read carefully:  I am using Visual Studio Express 2012 tools.  Under choose toolbox items, browse Net framework components and COM components.  I am not  searching \Windows\System32\ for anything beginning with "Geo".

    Ron Chandler

    I read what you wrote.

    I don't have VS 2012, but in VS 2015, when I open the Add Reference dialog, the only options are Assemblies, Projects, Shared Projects, COM , and Browse. If I choose Browse, I can open a standard OpenFileDialog that defaults to \Windows\System32\ and shows all files with relevant filetypes (.dll, .tlb, .exe, etc.) and does not filter out files that are not valid references.

    Tuesday, December 22, 2015 11:31 PM
  • The reference is not there anywhere.  To start at the top, I am simply trying to use the geolocation tools to look up my coordinates and (perhaps) show a map of where I am as I move from place to place around the U.S. and Africa.  I will find it hard to believe that a Visual Studio Express 2012 project cannot do this.

    Thanks.  Great to hear from you, Frank

    Ron


    Ron Chandler

    Tuesday, December 22, 2015 11:35 PM
  • The reference is not there anywhere.  To start at the top, I am simply trying to use the geolocation tools to look up my coordinates and (perhaps) show a map of where I am as I move from place to place around the U.S. and Africa.  I will find it hard to believe that a Visual Studio Express 2012 project cannot do this.

    Thanks.  Great to hear from you, Frank

    Ron


    Ron Chandler

    And you also - happy holidays!

    *****

    It seems to me that you're trying to drive a square peg into a round hole. It's not a dotNET assembly, so ...


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Tuesday, December 22, 2015 11:37 PM
  • OK.  I guess it cannot be done in a Vb application.

    Have a great holiday season.

    Ron Chandler


    Ron Chandler

    Tuesday, December 22, 2015 11:44 PM
  • OK.  I guess it cannot be done in a Vb application.

    Have a great holiday season.

    Ron Chandler


    Ron Chandler


    I'll look into some other way to do this - I'm not sure what I'll come up with, and I'm sure it won't be as robust as the one from Microsoft, but maybe I can come up with something anyway.

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Tuesday, December 22, 2015 11:53 PM
  • Thanks again!  FYI: I see a lot of Java code for this.

    Ron Chandler

    Tuesday, December 22, 2015 11:58 PM
  • Thanks again!  FYI: I see a lot of Java code for this.

    Ron Chandler


    I don't know what I'll come up with yet! ;-)

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 12:09 AM
  • Just  quick note:  Check out the following:

    http://www.w3schools.com/html/html5_geolocation.asp

    It works for me using their on-line test, but if I paste the HTML into notepad and save it as an HTML file, it doesn't quite work.

    Ron


    Ron Chandler

    Wednesday, December 23, 2015 12:10 AM
  • Just  quick note:  Check out the following:

    http://www.w3schools.com/html/html5_geolocation.asp

    It works for me using their on-line test, but if I paste the HTML into notepad and save it as an HTML file, it doesn't quite work.

    Ron


    Ron Chandler

    I do have in mind to use API's and several that I've used over the years, I think, might be combined to do the job -- maybe.

    Tell me specifically what you'd want back. I assume you want it to figure out what your IP address is based on your internet connection or did you have something else in mind?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 12:14 AM
  • I really want to get my gps coordinates and (perhaps) a google map of my location.

    Ron Chandler

    Wednesday, December 23, 2015 1:09 AM
  • I really want to get my gps coordinates and (perhaps) a google map of my location.

    What device is providing the GPS information?   Generally, no API is required to access a GPS device.  To load a google map at your location you will likely use a Google API.

    Wednesday, December 23, 2015 1:14 AM
  • I really want to get my gps coordinates and (perhaps) a google map of my location.

    Ron Chandler

    Ron,

    Try this to start with (it's based on your public IP which comes from a website):

    Option Strict On Option Explicit On Option Infer Off Imports System.IO Imports System.Net Namespace Geo Public Interface ILatLon ReadOnly Property Latitude() As Double ReadOnly Property Longitude() As Double End Interface Public Class GeoData Implements ILatLon Private _publicIP As String Private _countryCode As String Private _countryName As String Private _regionCode As String Private _regionName As String Private _city As String Private _zipCode As String Private _timeZone As String Private _latitude As Double Private _longitude As Double Private _metroCode As String Private Sub New() End Sub Public ReadOnly Property City As String Get Return _city End Get End Property Public ReadOnly Property CountryCode As String Get Return _countryCode End Get End Property Public ReadOnly Property CountryName As String Get Return _countryName End Get End Property Public ReadOnly Property Latitude As Double _ Implements ILatLon.Latitude Get Return _latitude End Get End Property Public ReadOnly Property Longitude As Double _ Implements ILatLon.Longitude Get Return _longitude End Get End Property Public ReadOnly Property MetroCode As String Get Return _metroCode End Get End Property Public ReadOnly Property PublicIP As String Get Return _publicIP End Get End Property Public ReadOnly Property RegionCode As String Get Return _regionCode End Get End Property Public ReadOnly Property RegionName As String Get Return _regionName End Get End Property Public ReadOnly Property TimeZone As String Get Return _timeZone End Get End Property Public ReadOnly Property ZipCode As String Get Return _zipCode End Get End Property Public Shared Function GetGeoInfo() As GeoData Dim retVal As GeoData = Nothing Try Const ipURL As String = "https://api.ipify.org/" Dim ip As String = ReturnTextFromURL(ipURL) If Not String.IsNullOrWhiteSpace(ip) Then Dim xDoc As XElement = XElement.Load("http://freegeoip.net/xml/" & ip.Trim) retVal = New GeoData With {._publicIP = ip.Trim} With retVal ._countryCode = xDoc...<CountryCode>.Value ._countryName = xDoc...<CountryName>.Value ._regionCode = xDoc...<RegionCode>.Value ._regionName = xDoc...<RegionName>.Value ._city = xDoc...<City>.Value ._zipCode = xDoc...<ZipCode>.Value ._timeZone = xDoc...<TimeZone>.Value ._latitude = CDbl(xDoc...<Latitude>.Value) ._longitude = CDbl(xDoc...<Longitude>.Value) ._metroCode = xDoc...<MetroCode>.Value End With End If Catch ex As Exception Throw End Try Return retVal End Function Private Shared Function ReturnTextFromURL(ByVal url As String) As String Dim retVal As String = "" Try Dim request As WebRequest = WebRequest.Create(url) Using response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse) Using dataStream As Stream = response.GetResponseStream Using reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() retVal = responseFromServer End Using End Using End Using Catch ex As Exception retVal = "" End Try Return retVal End Function End Class End Namespace


    To test it, I compiled it to a .dll and then added a reference to it:

    Option Strict On Option Explicit On Option Infer Off Imports GeoInfo Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load Dim myGeoData As Geo.GeoData = Geo.GeoData.GetGeoInfo Stop End Sub End Class


    Here's my result:

    Is this close to what you want?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 1:17 AM
  • Generally, no API is required to access a GPS device.

    Acamar,

    Would you tell me more about this please?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 1:43 AM
  • Would you tell me more about this please?

    If a GPS device is connected to your desktop PC then you will read your current location using the serial port (real or virtual) that the device is connected to.   The SerialPort component in .Net gives you the required access.  There is no API involved.

    An API might be required if you need to read the GPS information from an embedded device (such as a phone or tablet), or if you want to get location information from something other than GPS.

    Wednesday, December 23, 2015 2:01 AM
  • If a GPS device is connected to your desktop PC then you will read your current location using the serial port (real or virtual) that the device is connected to.   The SerialPort component in .Net gives you the required access.  There is no API involved.

    An API might be required if you need to read the GPS information from an embedded device (such as a phone or tablet), or if you want to get location information from something other than GPS.

    Ah ok - that makes sense.

    Thanks for the info. :)


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 2:03 AM
  • I want to try it, but I don't exactly know how to compile the first part as a .dll.  Is it a separate project with just a class library?  Tried to copy and paste code and cannot move forward.

    I think my public IP address is 10.237.139.72.  Does that sound right?


    Ron Chandler

    Wednesday, December 23, 2015 2:04 AM
  • I want to try it, but I don't exactly know how to compile the first part as a .dll.  Is it a separate project with just a class library?  Tried to copy and paste code and cannot move forward.

    I think my public IP address is 10.237.139.72.  Does that sound right?


    Ron Chandler

    Ron,

    I should have thought to do this to start with. I've zipped up the project folder and uploaded it here:

    http://www.fls-online.com/VBNet_Forum/12-22-15/Test_GetGeoInfo.zip

    When you download that, you'll then need to extract the folder somewhere. Following that when you open it in VisualStudio, it will prompt you to convert it (I'm using VS2010 / framework 4.0).

    Try that please?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 2:12 AM
  • Got the download and extracted the files.  When I double-click the sln, it shows that GeoInfo is unavailable.

    Ron Chandler

    Wednesday, December 23, 2015 2:33 AM
  • Got the download and extracted the files.  When I double-click the sln, it shows that GeoInfo is unavailable.

    Ron Chandler

    That's a little odd, but let's play this out:

    In Solution Explorer, you should see the class library:

    If you'll now right-click on that, you'll see some options so choose to view the code:

    When you see the code, choose to rebuild it:

    Following that, try it and it should work. If it doesn't, then look at the code in Form1. The imports statement is near the top - does it show a "squiggly" line there?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 2:42 AM
  • Right-click on Geo.vb produces choices: Open, Cut, Copy, delete, and Properties.  Open is highlighted, so I chose it.  The code appears, looks fine, no form, and no build option appears.  My software is very different from what you have shown.

    Ron Chandler

    Wednesday, December 23, 2015 2:55 AM
  • Right-click on Geo.vb produces choices: Open, Cut, Copy, delete, and Properties.  Open is highlighted, so I chose it.  The code appears, looks fine, no form, and no build option appears.  My software is very different from what you have shown.

    Ron Chandler

    I'm not sure what the issue is, but for now there's another way:

    In your form's code (either mine or your original one), go to the end of the code where you see "End Class". At the end of that line, type in a few blank lines then paste the code from the class library there.

    Remove the imports statement and then the code that I showed in Form1 will need to be changed around a little, but not much. Try that please?

    It baffles me why it didn't just work to start with though. I really don't understand that (nor do I understand what you're seeing now).


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 2:58 AM
  • Right-click on Geo.vb produces choices: Open, Cut, Copy, delete, and Properties.  Open is highlighted, so I chose it.  The code appears, looks fine, no form, and no build option appears.  My software is very different from what you have shown.

    Ron Chandler

    If all of that fails (why, I don't know), then here's another way:

    The .dll file is zipped up here. Download it and extract it somewhere, then add a reference to it.

    That should then let my example in Form1 run without a problem (fingers crossed here, nothing else seems right so far!)


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 3:05 AM
  • I had my main application code open when I did a right-click on Geo.vb and selected run.  The code was added to my main application!  I compiled the whole thing and it runs as normal.  Maybe that's an alternative to including a .dll?

    Ron Chandler

    Wednesday, December 23, 2015 3:14 AM
  • I had my main application code open when I did a right-click on Geo.vb and selected run.  The code was added to my main application!  I compiled the whole thing and it runs as normal.  Maybe that's an alternative to including a .dll?

    Ron Chandler


    I'm not really following what you did, but did the result data look like what you wanted to get from it?

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 3:17 AM
  • Looks like it didn't really become part of the project, so I removed it.

    I downloaded the .dll and added it as a reference to my main project.  Now, the statement:

            Dim myGeoData As Geo.GeoData = Geo.GeoData.GetGeoInfo

    returns data.  but how is the _publicIP introduced?


    Ron Chandler

    Wednesday, December 23, 2015 3:45 AM
  • Dim myGeoData As Geo.GeoData = Geo.GeoData.GetGeoInfo

    returns data.  but how is the _publicIP introduced?


    Ron Chandler

    It's getting your public IP from here:

    https://api.ipify.org/

    Is it wrong?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 3:50 AM
  • I think my ip is 10.237.139.72.  The returned data has no city or zip code and the public Ip is:

    70.145.52.225 - that seems wrong.

     

    Ron Chandler

    Wednesday, December 23, 2015 4:05 AM
  • I think my ip is 10.237.139.72.  The returned data has no city or zip code and the public Ip is:

    70.145.52.225 - that seems wrong.

     

    Ron Chandler

    Dang, I don't know.

    Mine seemed to nail it exactly.

    I'll do more with it tomorrow though, it's late here now.

    If you feel like explaining what you want as the next part then I'll give some thought to that also. I'll add in an overload so that you can tell it the IP address rather than having it look it up using that site.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 4:08 AM
  • Tomorrow sounds good.  Thanks a ton!

    Ron Chandler

    Wednesday, December 23, 2015 4:14 AM
  • I think my ip is 10.237.139.72.  The returned data has no city or zip code and the public Ip is:

    70.145.52.225 - that seems wrong.

    10... is a private address.  Your public address is likely correct (BellSouth, IIRC), but might not have location information attached to it.

    Wednesday, December 23, 2015 4:36 AM
  • Tomorrow sounds good.  Thanks a ton!

    Ron Chandler

    Ron,

    Given what Acamar just said, do you think it's even worth pursuing further? It seems to work here but if it doesn't work there (for whatever reason) then I don't see any use in it, do you?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 4:52 AM
  • Good point!  In response to what I really want - It's to duplicate the "try it" processes found on:

    http://www.w3schools.com/html/html5_geolocation.asp

    It's neat stuff that I would find very useful for worldwide travel.

    If you have any ideas along those lines, please let me know.  Otherwise I appreciate all that you have done to help!


    Ron Chandler

    Wednesday, December 23, 2015 3:05 PM
  • Good point!  In response to what I really want - It's to duplicate the "try it" processes found on:

    http://www.w3schools.com/html/html5_geolocation.asp

    It's neat stuff that I would find very useful for worldwide travel.

    If you have any ideas along those lines, please let me know.  Otherwise I appreciate all that you have done to help!


    Ron Chandler

    Ron,

    What do you think about this: If the IP won't expose the location information, what about you typing in the address and then I can use Bing Map's API to get the data?

    You'll need to get an API key but it's free and I'll explain how to do that.

    Your thoughts?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 3:19 PM
  • Good point!  In response to what I really want - It's to duplicate the "try it" processes found on:

    http://www.w3schools.com/html/html5_geolocation.asp

    It's neat stuff that I would find very useful for worldwide travel.

    If you have any ideas along those lines, please let me know.  Otherwise I appreciate all that you have done to help!


    Ron Chandler

    This is the sort of information that I can get from Bing Maps:

    http://www.fls-online.com/VBNet_Forum/12-23-15/ExampleAddressInfoFromBingMaps.xml

    Obviously I couldn't give you the actual URL because it would expose my API key, but that should give you the idea.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 3:36 PM
  • Looks like a good idea!  Getting a key may be difficult.  No dead end yet!

    Ron Chandler

    Wednesday, December 23, 2015 5:04 PM
  • Looks like a good idea!  Getting a key may be difficult.  No dead end yet!

    Ron Chandler

    I'll need to redo this then, and I have in mind that it'll always use the Bing data even if it's able to figure out your IP automatically. That way the end result is always the same structure. Agree?

    You said that you want to use this to keep up when traveling - so do you think it would be worthwhile to set this up as a collection class then? I can then have it persist the data to a binary file and/or XML, but the point is that it'll keep up with whatever you add or remove.

    Your thoughts?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 5:13 PM
  • No need to do a collection class.  I will only use this when I connect my PC at various places where I stay (RV parks, Lodges, etc.)

    Ron Chandler

    Wednesday, December 23, 2015 5:17 PM
  • No need to do a collection class.  I will only use this when I connect my PC at various places where I stay (RV parks, Lodges, etc.)

    Ron Chandler

    Well that's fine with me (and easier on my end), but are you sure?

    Didn't you want to have it output a map of your traveling, like from point A to point B, etc.?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 5:19 PM
  • Not interested in tracking travel.  Only spots where we stay.

    Ron Chandler

    Wednesday, December 23, 2015 5:35 PM
  • Not interested in tracking travel.  Only spots where we stay.

    Ron Chandler

    Ok, I'll get started then.

    It'll likely be tomorrow getting this back to you but I think I can make it work.

    In the meantime, have a look here to see how to get the Bing map API key. I did it several years ago and though I don't remember the details, I remember that it wasn't too difficult.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 5:41 PM
  • Not interested in tracking travel.  Only spots where we stay.

    Ron Chandler

    Ok, I have something for you to try.

    The project folder is zipped up and uploaded here. At the top of Form1, you'll see where you need to put your Bing API key so be sure to replace that or it won't work.

    In my test run of it, I gave it my address information (it's actually my old address, not my current one) and in the "Completed" event handler sub, it returned the following:

    I have the code shown here (if you want to copy from that, click the link at the top of that page and copy the unformatted text version) and if you'll look at the "Start" method, I'll explain what you're seeing and what it means:

    Public Sub Start(ByVal bingAPIkey As String, _
        Optional ByVal address As String = Nothing, _
        Optional ByVal city As String = Nothing, _
        Optional ByVal state As String = Nothing, _
        Optional ByVal zipcode As String = Nothing)
    
    

    If you give it only the API key, then it will do what it did last night and [attempt to] get your location data from your IP address. It uses the very same websites as it did from last night.

    If you give it more information about your location - and the more the better - then it will attempt to get the data from Bing Maps via their API. The more information you give it, the more accurate the result.

    Will you give that a try please?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 8:25 PM
  • By the way, if you don't give it a valid Bing Map API key, you'll get this:


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 9:10 PM
  • I cannot compile your code to test it and see how it works.  I copied the code into my main project and it compiles OK, however.  I cannot test it because I cannot see how you made the call to GeoInfo.Geo.GeoData.OperationCompleteEventArgs.


    Ron Chandler


    Wednesday, December 23, 2015 10:50 PM
  • Ron,

    Modify your post please - you're showing the API key.

    *****

    From last night, that won't work - it doesn't know your location. You need to give it something to let Bing Maps API find the location. Look at the example I used in Form1.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 11:20 PM
  • I cannot compile your code to test it and see how it works.  I copied the code into my main project and it compiles OK, however.  I cannot test it because I cannot see how you made the call to GeoInfo.Geo.GeoData.OperationCompleteEventArgs.


    Ron Chandler


    I've removed the IP from the results but I can put it back if you want me to.

    Using what you showed though, this is how to do it (use your API key and your address information):

    Option Strict On Option Explicit On Option Infer Off Imports GeoInfo Public Class Form1 Private Const bingAPIkey As String = "API Key Here" Private WithEvents geoData As Geo.GeoData Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load ' ...initialization here, if any End Sub Private Sub _ ButtonGetLocationFromInternet_Click(sender As System.Object, _ e As System.EventArgs) _ Handles ButtonGetLocationFromInternet.Click ButtonGetLocationFromInternet.Enabled = False With Me .Cursor = Cursors.WaitCursor .Refresh() End With geoData = New Geo.GeoData geoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055") End Sub Private Sub _ geoData_OperationComplete(sender As Object, _ e As GeoInfo.Geo.GeoData.OperationCompleteEventArgs) _ Handles geoData.OperationComplete If e.OperationException IsNot Nothing Then MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _ vbCrLf, e.OperationException.Message), _ "Program Error", MessageBoxButtons.OK, _ MessageBoxIcon.Warning) Else TextBoxInternetCity.Text = e.Locality TextBoxInternetZip.Text = e.PostalCode TextBoxInternetLat.Text = e.Latitude.ToString("f6") TextBoxInternetLon.Text = e.Longitude.ToString("f6") End If End Sub End Class



    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Wednesday, December 23, 2015 11:53 PM
  • Still no go.  Imports GeoInfo not there. Is it supposed to be part of the new code?

    Ron Chandler

    Thursday, December 24, 2015 1:15 AM
  • Still no go.  Imports GeoInfo not there. Is it supposed to be part of the new code?

    Ron Chandler

    Yes.

    This is the same situation we were in last night. Try whatever you did last night again please?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 1:17 AM
  • Cannot get there.  Yesterday's code had 'Public Shared Function GetGeoInfo() As GeoData' in the Namespace Geo.  Today's code under Namespace Geo does not have it.  Yesterday's code has:

    '                    With retVal
    '                        ._countryCode = xDoc...<CountryCode>.Value
    '                        ._countryName = xDoc...<CountryName>.Value
    '                        ._regionCode = xDoc...<RegionCode>.Value
    '                        ._regionName = xDoc...<RegionName>.Value
    '                        ._city = xDoc...<City>.Value
    '                        ._zipCode = xDoc...<ZipCode>.Value
    '                        ._timeZone = xDoc...<TimeZone>.Value
    '                        ._latitude = CDbl(xDoc...<Latitude>.Value)
    '                        ._longitude = CDbl(xDoc...<Longitude>.Value)
    '                        ._metroCode = xDoc...<MetroCode>.Value
    '                    End With

    Of course this isn't compatible with the new Bing structure


    Ron Chandler

    Thursday, December 24, 2015 1:46 AM
  • Cannot get there.  Yesterday's code had 'Public Shared Function GetGeoInfo() As GeoData' in the Namespace Geo.  Today's code under Namespace Geo does not have it.  Yesterday's code has:

    '                    With retVal
    '                        ._countryCode = xDoc...<CountryCode>.Value
    '                        ._countryName = xDoc...<CountryName>.Value
    '                        ._regionCode = xDoc...<RegionCode>.Value
    '                        ._regionName = xDoc...<RegionName>.Value
    '                        ._city = xDoc...<City>.Value
    '                        ._zipCode = xDoc...<ZipCode>.Value
    '                        ._timeZone = xDoc...<TimeZone>.Value
    '                        ._latitude = CDbl(xDoc...<Latitude>.Value)
    '                        ._longitude = CDbl(xDoc...<Longitude>.Value)
    '                        ._metroCode = xDoc...<MetroCode>.Value
    '                    End With

    Of course this isn't compatible with the new Bing structure


    Ron Chandler

    No, you're right - the code changed entirely. It's not at all like I originally had it.

    Have you tried importing in the .dll file? That should work.

    *****

    As a last resort measure I can write a whole program, compile it, create a signed installer and all of that. It'll take several days, but I can do it. It's not what I wanted to do on my vacation, but I will if nothing else works.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 1:51 AM
  • Nope.  Code:

        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            Geo.GeoData = New Geo.GeoData
            Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

    Something is still is wrong.  Lines:

            Geo.GeoData = New Geo.GeoData
            Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")

    Are in error: 'GeoData is a type in Geo and cannot be used as an expression'


    Ron Chandler

    Thursday, December 24, 2015 2:16 AM
  • Nope.  Code:

        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            Geo.GeoData = New Geo.GeoData
            Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

    Something is still is wrong.  Lines:

            Geo.GeoData = New Geo.GeoData
            Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")

    Are in error: 'GeoData is a type in Geo and cannot be used as an expression'


    Ron Chandler

    It doesn't look like you've declared it.

    Look again that the code that I showed a few posts up please. In my code, there's a form scoped variable named "geoData" which is declared "WithEvents".

    Do you have that?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 2:27 AM
  • Added it as follows:

    Public Class LocationData

        Private WithEvents geoData As Geo.GeoData

    Got exactly the same errors as last post


    Ron Chandler

    Thursday, December 24, 2015 2:36 AM
  • Added it as follows:

    Public Class LocationData

        Private WithEvents geoData As Geo.GeoData

    Got exactly the same errors as last post


    Ron Chandler


    Is anything showing as a compile error? Is there a squiggly line under anything? Look in the references and make sure that the assembly is shown there and that it's not shown as "Not Found" (or whatever it shows).

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 2:39 AM
  • Yes.  Squiggly line under 'Geo.GeoData' of statement 'Geo.GeoData = New Geo.GeoData' and also a squiggly line under 'Geo.GeoData.Start' of statement:

    'Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")'


    Ron Chandler

    Thursday, December 24, 2015 2:43 AM
  • Yes.  Squiggly line under 'Geo.GeoData' of statement 'Geo.GeoData = New Geo.GeoData' and also a squiggly line under 'Geo.GeoData.Start' of statement:

    'Geo.GeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")'


    Ron Chandler

    Ok, look in the references (double-click on "MyProject" and select the References tab).

    Do you see the assembly shown there? I'm guessing that it's shown as "Not Found" or something similar?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 2:48 AM
  • I see GeoInfo and GeoInfo.Geo under imported namespaces.  Both boxes are unchecked.

    Ron Chandler

    Thursday, December 24, 2015 2:54 AM
  • GeoInfo also appears in the references box - nothing shows missing.

    Ron Chandler

    Thursday, December 24, 2015 2:57 AM
  • I see GeoInfo and GeoInfo.Geo under imported namespaces.  Both boxes are unchecked.

    Ron Chandler

    Obviously your version of VS is different than mine, but this is what mine looks like:

    Here's what I'll suggest (understand that I'm not seeing the same thing that you are):

    There's a button somewhere there about removing the reference. Click the button to remove the reference then click the button to add a reference.

    When you do, choose "Browse" and browse to the other subfolder that's in what you unzipped. Use the one that's in the bin\Release folder (there will only be one .dll file there).

    Try that please?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:01 AM
  • Removed it, then added it from the bin folder, got exactly the same errors.

    Ron Chandler

    Thursday, December 24, 2015 3:07 AM
  • Removed it, then added it from the bin folder, got exactly the same errors.

    Ron Chandler

    Dang...

    Let's look at it again tomorrow, but I can't think of a reason it's not working.

    Do you want me to put a full-fledged program together like I talked about earlier? It'll take several days but I can do that.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:11 AM
  • Obviously, this is not any kind of emergency.  I have plenty of time.  I just appreciate your un-tiring efforts to make it work.  I am very patient.  Maybe tomorrow.  We have no big plans for Christmas eve.

    Best wishes, and thanks again


    Ron Chandler

    Thursday, December 24, 2015 3:18 AM
  • Obviously, this is not any kind of emergency.  I have plenty of time.  I just appreciate your un-tiring efforts to make it work.  I am very patient.  Maybe tomorrow.  We have no big plans for Christmas eve.

    Best wishes, and thanks again


    Ron Chandler

    Try this before we give up please:

    Option Strict On Option Explicit On Option Infer Off 'Imports GeoInfo Imports System.IO Imports System.Net Imports <xmlns:bing="http://schemas.microsoft.com/search/local/ws/rest/v1"> Public Class Form1 Private Const bingAPIkey As String = "API Key Here" Private WithEvents geoData As Geo.GeoData Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load ' ...initialization here, if any End Sub Private Sub _ ButtonGetLocationFromInternet_Click(sender As System.Object, _ e As System.EventArgs) _ Handles ButtonGetLocationFromInternet.Click ButtonGetLocationFromInternet.Enabled = False With Me .Cursor = Cursors.WaitCursor .Refresh() End With geoData = New Geo.GeoData geoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055") End Sub Private Sub _ geoData_OperationComplete(sender As Object, _ e As Geo.GeoData.OperationCompleteEventArgs) _ Handles geoData.OperationComplete If e.OperationException IsNot Nothing Then MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _ vbCrLf, e.OperationException.Message), _ "Program Error", MessageBoxButtons.OK, _ MessageBoxIcon.Warning) Else TextBoxInternetCity.Text = e.Locality TextBoxInternetZip.Text = e.PostalCode TextBoxInternetLat.Text = e.Latitude.ToString("f6") TextBoxInternetLon.Text = e.Longitude.ToString("f6") End If End Sub End Class Namespace Geo Public Interface ILatLon ''' <summary> ''' Gets the latitude for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property Latitude() As Double ''' <summary> ''' Gets the longitude for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property Longitude() As Double End Interface Public Class GeoData Private Class BGW_Instructions Public BingAPIkey As String Public AddressData As BingData End Class Private Class BingData Public AddressLine As String Public AdminDistrict As String Public AdminDistrict2 As String Public CountryRegion As String Public Locality As String Public PostalCode As String Public Latitude As Double Public Longitude As Double End Class Public ReadOnly Property OperationCurrentlyBusy As Boolean Get If bgw Is Nothing Then Return False Else Return bgw.IsBusy End If End Get End Property Public Sub Start(ByVal bingAPIkey As String, _ Optional ByVal address As String = Nothing, _ Optional ByVal city As String = Nothing, _ Optional ByVal state As String = Nothing, _ Optional ByVal zipcode As String = Nothing) Try If OperationCurrentlyBusy Then Throw New ArgumentException("The operation is currently busy.") ElseIf String.IsNullOrWhiteSpace(bingAPIkey) Then Throw New ArgumentException("The Bing Maps API key cannot be null or empty.") Else Dim bd As BingData = Nothing If Not String.IsNullOrWhiteSpace(address) OrElse _ Not String.IsNullOrWhiteSpace(city) OrElse _ Not String.IsNullOrWhiteSpace(state) OrElse _ Not String.IsNullOrWhiteSpace(zipcode) Then bd = New BingData _ With {.AddressLine = address, _ .AdminDistrict = state, _ .Locality = city, _ .PostalCode = zipcode} End If _operationException = Nothing Dim instructions As New _ BGW_Instructions _ With {.BingAPIkey = bingAPIkey.Trim} bgw = _ New System.ComponentModel.BackgroundWorker _ With {.WorkerSupportsCancellation = True} If bd IsNot Nothing Then instructions.AddressData = bd End If bgw.RunWorkerAsync(instructions) End If Catch ex As Exception Throw End Try End Sub Public Event OperationComplete(ByVal sender As Object, ByVal e As OperationCompleteEventArgs) Protected Overridable Sub OnOperationCompleted() RaiseEvent OperationComplete(Me, New OperationCompleteEventArgs) End Sub Private WithEvents bgw As System.ComponentModel.BackgroundWorker Private Shared _operationException As Exception Private Shared _addressLine As String Private Shared _adminDistrict As String Private Shared _adminDistrict2 As String Private Shared _countryRegion As String Private Shared _locality As String Private Shared _postalCode As String Private Shared _latitude As Double Private Shared _longitude As Double Private Sub _ bgw_DoWork(sender As Object, _ e As System.ComponentModel.DoWorkEventArgs) _ Handles bgw.DoWork Try If e.Argument IsNot Nothing Then Dim instructions As BGW_Instructions = DirectCast(e.Argument, BGW_Instructions) If instructions IsNot Nothing Then If instructions.AddressData IsNot Nothing Then Dim sb As New System.Text.StringBuilder("http://dev.virtualearth.net/REST/v1/Locations/") If Not String.IsNullOrWhiteSpace(instructions.AddressData.AddressLine) Then sb.Append(instructions.AddressData.AddressLine.Trim.Replace(" "c, "%20") & ","c) End If If Not String.IsNullOrWhiteSpace(instructions.AddressData.Locality) Then sb.Append(instructions.AddressData.Locality.Trim.Replace(" "c, "%20") & ","c) End If If Not String.IsNullOrWhiteSpace(instructions.AddressData.AdminDistrict) Then sb.Append(instructions.AddressData.AdminDistrict.Trim.Replace(" "c, "%20") & ","c) End If If Not String.IsNullOrWhiteSpace(instructions.AddressData.PostalCode) Then sb.Append(instructions.AddressData.PostalCode.Trim.Replace(" "c, "%20")) End If If sb.ToString.EndsWith(","c) Then sb.Remove(sb.Length - 1, 1) End If sb.Append("?o=xml&key=" & instructions.BingAPIkey) Dim bd As BingData = GetBingData(sb.ToString) If bd IsNot Nothing Then e.Result = bd End If Else Dim ip As String = GetIP() If Not String.IsNullOrWhiteSpace(ip) Then Dim xDoc As XElement = XElement.Load("http://freegeoip.net/xml/" & ip.Trim) Dim cityName As String = xDoc...<City>.Value Dim regionName As String = xDoc...<RegionName>.Value Dim zipCode As String = xDoc...<ZipCode>.Value Dim sb As New System.Text.StringBuilder("http://dev.virtualearth.net/REST/v1/Locations/") sb.Append(cityName.Trim.Replace(" "c, "%20") & ","c) sb.Append(regionName.Trim.Replace(" "c, "%20") & ","c) sb.Append(zipCode.Trim.Replace(" "c, "%20")) sb.Append("?o=xml&key=" & instructions.BingAPIkey) Dim bd As BingData = GetBingData(sb.ToString) If bd IsNot Nothing Then e.Result = bd End If End If End If End If End If Catch ex As Exception _operationException = ex bgw.CancelAsync() End Try End Sub Private Sub _ bgw_RunWorkerCompleted(sender As Object, _ e As System.ComponentModel.RunWorkerCompletedEventArgs) _ Handles bgw.RunWorkerCompleted If e.Result IsNot Nothing Then Dim bd As BingData = DirectCast(e.Result, BingData) If bd IsNot Nothing Then _addressLine = bd.AddressLine _adminDistrict = bd.AdminDistrict _adminDistrict2 = bd.AdminDistrict2 _countryRegion = bd.CountryRegion _locality = bd.Locality _postalCode = bd.PostalCode _latitude = bd.Latitude _longitude = bd.Longitude End If End If OnOperationCompleted() Dispose() End Sub Private Delegate Function GetIPDelegate() As String Private Function GetIP() As String Dim retVal As String = Nothing Try Const ipURL As String = "https://api.ipify.org/" Dim ip As String = GetTextFromURL(ipURL) If Not String.IsNullOrWhiteSpace(ip) Then retVal = ip End If Catch ex As Exception Throw End Try Return retVal End Function Private Delegate Function _ GetBingDataDelegate(ByVal url As String) As BingData Private Function GetBingData(ByVal url As String) As BingData Dim retVal As BingData = Nothing Try If Not String.IsNullOrWhiteSpace(url) Then Dim bingDoc As XElement = XElement.Load(url) Dim lat As Nullable(Of Double) = Nothing Dim lon As Nullable(Of Double) = Nothing For Each latLon As XElement In bingDoc...<bing:Point> If Double.TryParse(latLon...<bing:Latitude>.Value, New Double) Then lat = CDbl(latLon...<bing:Latitude>.Value) End If If Double.TryParse(latLon...<bing:Longitude>.Value, New Double) Then lon = CDbl(latLon...<bing:Longitude>.Value) End If Exit For Next If lat.HasValue AndAlso lon.HasValue Then retVal = New BingData With {.Latitude = CDbl(lat), .Longitude = CDbl(lon)} With retVal For Each address As XElement In bingDoc...<bing:Address> .AddressLine = address...<bing:AddressLine>.Value If String.IsNullOrWhiteSpace(.AddressLine) Then .AddressLine = "Unknown" End If .AdminDistrict = address...<bing:AdminDistrict>.Value If String.IsNullOrWhiteSpace(.AdminDistrict) Then .AdminDistrict = "Unknown" End If .AdminDistrict2 = address...<bing:AdminDistrict2>.Value If String.IsNullOrWhiteSpace(.AdminDistrict2) Then .AdminDistrict2 = "Unknown" End If .CountryRegion = address...<bing:CountryRegion>.Value If String.IsNullOrWhiteSpace(.CountryRegion) Then .CountryRegion = "Unknown" End If .Locality = address...<bing:Locality>.Value If String.IsNullOrWhiteSpace(.Locality) Then .Locality = "Unknown" End If .PostalCode = address...<bing:PostalCode>.Value If String.IsNullOrWhiteSpace(.PostalCode) Then .PostalCode = "Unknown" End If Next End With End If End If Catch ex As Exception Throw End Try Return retVal End Function Private Function GetTextFromURL(ByVal url As String) As String Dim retVal As String = "" Try Dim request As WebRequest = WebRequest.Create(url) Using response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse) Using dataStream As Stream = response.GetResponseStream Using reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() retVal = responseFromServer End Using End Using End Using Catch ex As Exception retVal = "" End Try Return retVal End Function Public Class OperationCompleteEventArgs Inherits EventArgs Implements ILatLon ''' <summary> ''' Gets the exception which was thrown during operation (if any). ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property OperationException As Exception Get Return _operationException End Get End Property ''' <summary> ''' Gets the street address for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property AddressLine As String Get Return _addressLine End Get End Property ''' <summary> ''' Gets the primary administation district for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property AdminDistrict As String Get Return _adminDistrict End Get End Property ''' <summary> ''' Gets the secondary administation district for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property AdminDistrict2 As String Get Return _adminDistrict2 End Get End Property ''' <summary> ''' Gets the country region for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property CountryRegion As String Get Return _countryRegion End Get End Property Public ReadOnly Property Latitude As Double _ Implements ILatLon.Latitude Get Return _latitude End Get End Property ''' <summary> ''' Gets the locality for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property Locality As String Get Return _locality End Get End Property Public ReadOnly Property Longitude As Double _ Implements ILatLon.Longitude Get Return _longitude End Get End Property ''' <summary> ''' Gets the postal code for this location. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property PostalCode As String Get Return _postalCode End Get End Property End Class Private Sub Dispose() If bgw IsNot Nothing Then bgw.Dispose() bgw = Nothing End If End Sub End Class End Namespace


    I don't like to do it this way but let me know if it works?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:22 AM
  • It works!  Now what?

    Ron Chandler

    Thursday, December 24, 2015 4:08 AM
  • I am using Visual Studio Express 2012 for desktop undr windows 10.  I am trying to add a reference to geolocation.dll.

    I get the following message:

    A reference to 'C\Windows\System32\Geolocation.dll' could not be added.  Please make sure that the file is accessable, and that it is a valid assembly or COM component.

    Help is appreciated.


    Ron Chandler


    It is a native DLL, and you just can't set reference to it through VS IDE.

    You may have to do what is in the link below.

    https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

    https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Geolocation

    You may have to treat it like it's a Win32 API

    http://www.c-sharpcorner.com/UploadFile/shrijeetnair/win32api12062005005528AM/win32api.aspx

    You may have to use Dependecywalker to look at the what methods and/or functions the DLL exposes.

    http://www.dependencywalker.com/

    • Proposed as answer by Naomi N Friday, December 25, 2015 1:08 AM
    Thursday, December 24, 2015 4:08 AM
  • It works!  Now what?

    Ron Chandler

    Good. :)

    I'm not fond of doing it that way, but at least it works.

    *****

    What more do you want it to do? A static map maybe?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 1:34 PM
  • What I mean is that I created a separate project using the code in your last post.  That code works, mine still has the compile errors.  I will now try to imbed your code.

    Ron Chandler

    Thursday, December 24, 2015 1:56 PM
  • What I mean is that I created a separate project using the code in your last post.  That code works, mine still has the compile errors.  I will now try to imbed your code.

    Ron Chandler


    I'll be in and out today but let me know how you fare.

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 2:00 PM
  • I finally found the compile error:

    solved it with:

        Dim myGeoData As Geo.GeoData

    at the form scope.  Now The geoData_OperationComplete event doesn't seem to fire do no results are returned.  Here is the code:

        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            myGeoData = New Geo.GeoData
            myGeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

        Private Sub geoData_OperationComplete(sender As Object, _
                                  e As Geo.GeoData.OperationCompleteEventArgs) _
                                  Handles geoData.OperationComplete
            If e.OperationException IsNot Nothing Then
                MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _
                                              vbCrLf, e.OperationException.Message), _
                                              "Program Error", MessageBoxButtons.OK, _
                                              MessageBoxIcon.Warning)
            Else
                TextBoxInternetCity.Text = e.Locality
                TextBoxInternetZip.Text = e.PostalCode
                TextBoxInternetLat.Text = e.Latitude.ToString("f6")
                TextBoxInternetLon.Text = e.Longitude.ToString("f6")
            End If
        End Sub


    Ron Chandler

    Thursday, December 24, 2015 3:05 PM
  • Ron,

    How about put a breakpoint on the line which starts it. Step into it and see if you can see what's going on.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:10 PM
  • Tried that, doesn't fire.  Put a breakpoint at Private Sub bgw_DoWork and stepped through. It looks like the data is there.  Put a breakpoint at Private Sub bgw_RunWorkerCompleted and results are there.  I think the problem is related to the statement 'Private WithEvents geoData As Geo.GeoData' at the form scope of my code.  The 'Private Sub geoData_OperationComplete' located there will not compile without it, but somehow the event doesn't progagate from your code.

    Ron Chandler

    Thursday, December 24, 2015 3:32 PM
  • Tried that, doesn't fire.  Put a breakpoint at Private Sub bgw_DoWork and stepped through. It looks like the data is there.  Put a breakpoint at Private Sub bgw_RunWorkerCompleted and results are there.  I think the problem is related to the statement 'Private WithEvents geoData As Geo.GeoData' at the form scope of my code.  The 'Private Sub geoData_OperationComplete' located there will not compile without it, but somehow the event doesn't progagate from your code.

    Ron Chandler


    I'll try to duplicate it but what is "myGeoData"? Would you show more of your code for that form please?

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:34 PM
  • my form - at the top:

    Imports GeoInfo

    Public Class LocationData

        Dim myGeoData As Geo.GeoData

        Private WithEvents geoData As Geo.GeoData

    The critical code is behind the following button:

        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            myGeoData = New Geo.GeoData
            myGeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

        Private Sub geoData_OperationComplete(sender As Object, _
                                  e As Geo.GeoData.OperationCompleteEventArgs) _
                                  Handles geoData.OperationComplete
            If e.OperationException IsNot Nothing Then
                MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _
                                              vbCrLf, e.OperationException.Message), _
                                              "Program Error", MessageBoxButtons.OK, _
                                              MessageBoxIcon.Warning)
            Else
                TextBoxInternetCity.Text = e.Locality
                TextBoxInternetZip.Text = e.PostalCode
                TextBoxInternetLat.Text = e.Latitude.ToString("f6")
                TextBoxInternetLon.Text = e.Longitude.ToString("f6")
            End If
        End Sub


    Ron Chandler

    Thursday, December 24, 2015 3:41 PM
  • Ron,

    Bear with me a while please. I'll see what I can come up with.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:46 PM
  • Solved it:

    Imports GeoInfo

    Public Class LocationData

        Private WithEvents myGeoData As Geo.GeoData
        Private Sub ButtonGetLocationFromInternet_Click(sender As Object, e As EventArgs) Handles ButtonGetLocationFromInternet.Click
            Me.Cursor = Cursors.WaitCursor
            myGeoData = New Geo.GeoData
            myGeoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")
            Me.Cursor = Cursors.Default
        End Sub

        Private Sub geoData_OperationComplete(sender As Object, _
                                  e As Geo.GeoData.OperationCompleteEventArgs) _
                                  Handles myGeoData.OperationComplete
            If e.OperationException IsNot Nothing Then
                MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _
                                              vbCrLf, e.OperationException.Message), _
                                              "Program Error", MessageBoxButtons.OK, _
                                              MessageBoxIcon.Warning)
            Else
                TextBoxInternetCity.Text = e.Locality
                TextBoxInternetZip.Text = e.PostalCode
                TextBoxInternetLat.Text = e.Latitude.ToString("f6")
                TextBoxInternetLon.Text = e.Longitude.ToString("f6")
            End If
        End Sub


    Ron Chandler

    Thursday, December 24, 2015 3:49 PM
  • Right,

    I was just changing that: Essentially you had the event subscribing to the wrong one.

    *****

    What do you want to do from here? Do you want me to do something with a map from Bing?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 3:53 PM
  • Yes, adding the map would be great.  By the way, please know that I have enjoyed having dialog with you.  It's a bit like drinking from a fire-hose, but I get a chance to have a wild ride up my learning curve!

    Maybe a new dialog should be in order (this one is verbose).  Should I start one with a question about the map?


    Ron Chandler

    Thursday, December 24, 2015 3:59 PM
  • Maybe a new dialog should be in order (this one is verbose).  Should I start one with a question about the map?

    That's up to you - it'll be a while before I have anything though.

    Years ago I did a fair amount with Bing Maps including the imagery, but I just don't remember how it all works now, so I'll have to do some studying first, then coding and testing.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 4:06 PM
  • I want to retrieve bing location data based on my public IPv4 address.  Is that possible?

    Ron Chandler

    Thursday, December 24, 2015 4:10 PM
  • I want to retrieve bing location data based on my public IPv4 address.  Is that possible?

    Ron Chandler


    That's what this will do if it can get location information from your IP -- which it couldn't do in your case. It worked with me, but it didn't for you... or did I miss something?

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 4:15 PM
  • I know it didn't work with old software, but I thought that the Bing mechanisms would behave differently.  For example if you go to http://whatismyipaddress.com/ you see your public IPv4 address along with a map of where my IP connection is - cool!  That would really help me because I don't know the address of the location where I stop.  The closest address is the location of my connected IP.  How does http://whatismyipaddress.com/ do it?

    Ron Chandler

    Thursday, December 24, 2015 4:29 PM
  • I know it didn't work with old software, but I thought that the Bing mechanisms would behave differently.  For example if you go to http://whatismyipaddress.com/ you see your public IPv4 address along with a map of where my IP connection is - cool!  That would really help me because I don't know the address of the location where I stop.  The closest address is the location of my connected IP.  How does http://whatismyipaddress.com/ do it?

    Ron Chandler

    That's a valid question and I don't know.

    I'll look into that later but I want to focus on the map stuff first.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 4:33 PM
  • Map stuff - great!  By the way, my interest is keen because we sometimes travel to places like Botswana or Swaziland where they do not have street addresses but sometimes we can connect to the Internet, so the only input we have would be our public IP address.  Make sense?

    Ron Chandler

    Thursday, December 24, 2015 5:04 PM
  • Map stuff - great!  By the way, my interest is keen because we sometimes travel to places like Botswana or Swaziland where they do not have street addresses but sometimes we can connect to the Internet, so the only input we have would be our public IP address.  Make sense?

    Ron Chandler

    Yes, and I'm fairly sure it will work in most places, but for whatever reason, yours there didn't work.

    I'll look into all of that later though...


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 5:09 PM
  • Map stuff - great!  By the way, my interest is keen because we sometimes travel to places like Botswana or Swaziland where they do not have street addresses but sometimes we can connect to the Internet, so the only input we have would be our public IP address.  Make sense?

    Ron Chandler

    Ok, I have something for you to try.

    The project folder is here, and following is what I've added:

    There are several image options and some of those you need to set (like the image size and the image type), and some I've set in code because I'm giving you ALL of the options as an instance of a nested class.

    Look at the code and you'll see what I mean, but following shows some of the results (by the way, the smallest zoom level and the largest zoom level are useless, but they're there anyway):

    Let me know what you think. :)


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 6:40 PM
  • I meant to add this also. If you look at the form's code:

    Option Strict On Option Explicit On Option Infer Off Imports GeoInfo Public Class Form1 Private Const bingAPIkey As String = "Bing Map API Key Here" Private WithEvents geoData As Geo.GeoData Private mapData As Geo.GeoData.MapURLs Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load With TrackBar_ZoomLevel .Minimum = 0 .Maximum = 21 .Value = 10 End With GroupBox_Maps.Enabled = False RadioButton_Map_Aerial.Checked = True With PictureBox1 .SizeMode = PictureBoxSizeMode.Zoom .WaitOnLoad = False End With With ProgressBar1 .Minimum = 0 .Maximum = 100 .Visible = False End With End Sub Private Sub _ ButtonGetLocationFromInternet_Click(sender As System.Object, _ e As System.EventArgs) _ Handles ButtonGetLocationFromInternet.Click ButtonGetLocationFromInternet.Enabled = False With Me .Cursor = Cursors.WaitCursor .Refresh() End With mapData = Nothing geoData = New Geo.GeoData ' geoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055") geoData.Start(bingAPIkey, Geo.GeoData.ImageType.Png, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height) End Sub Private Sub _ RadioButton_Map_Click(sender As Object, _ e As System.EventArgs) _ Handles RadioButton_Map_Aerial.Click, _ RadioButton_Map_AerialWithLabels.Click, _ RadioButton_Map_Road.Click PictureBox1.Image = Nothing If mapData IsNot Nothing Then Dim instance As Geo.GeoData.MapURLs.MapZoomURL = Nothing If RadioButton_Map_Aerial.Checked Then instance = mapData.AerialMap ElseIf RadioButton_Map_AerialWithLabels.Checked Then instance = mapData.AerialWithLabelsMap Else instance = mapData.RoadMap End If If instance IsNot Nothing Then With ProgressBar1 .Value = 0 .Visible = True .Refresh() End With Select Case TrackBar_ZoomLevel.Value Case 0 PictureBox1.LoadAsync(instance.MapSize00) Case 1 PictureBox1.LoadAsync(instance.MapSize01) Case 2 PictureBox1.LoadAsync(instance.MapSize02) Case 3 PictureBox1.LoadAsync(instance.MapSize03) Case 4 PictureBox1.LoadAsync(instance.MapSize04) Case 5 PictureBox1.LoadAsync(instance.MapSize05) Case 6 PictureBox1.LoadAsync(instance.MapSize06) Case 7 PictureBox1.LoadAsync(instance.MapSize07) Case 8 PictureBox1.LoadAsync(instance.MapSize08) Case 9 PictureBox1.LoadAsync(instance.MapSize09) Case 10 PictureBox1.LoadAsync(instance.MapSize10) Case 11 PictureBox1.LoadAsync(instance.MapSize11) Case 12 PictureBox1.LoadAsync(instance.MapSize12) Case 13 PictureBox1.LoadAsync(instance.MapSize13) Case 14 PictureBox1.LoadAsync(instance.MapSize14) Case 15 PictureBox1.LoadAsync(instance.MapSize15) Case 16 PictureBox1.LoadAsync(instance.MapSize16) Case 17 PictureBox1.LoadAsync(instance.MapSize17) Case 18 PictureBox1.LoadAsync(instance.MapSize18) Case 19 PictureBox1.LoadAsync(instance.MapSize19) Case 20 PictureBox1.LoadAsync(instance.MapSize20) Case 21 PictureBox1.LoadAsync(instance.MapSize21) End Select End If End If End Sub Private Sub _ TrackBar_ZoomLevel_ValueChanged(sender As Object, _ e As System.EventArgs) _ Handles TrackBar_ZoomLevel.ValueChanged RadioButton_Map_Click(Nothing, Nothing) End Sub Private Sub _ PictureBox1_LoadProgressChanged(sender As Object, _ e As System.ComponentModel.ProgressChangedEventArgs) _ Handles PictureBox1.LoadProgressChanged With ProgressBar1 .Visible = True .Value = e.ProgressPercentage .Refresh() End With End Sub Private Sub _ PictureBox1_LoadCompleted(sender As Object, _ e As System.ComponentModel.AsyncCompletedEventArgs) _ Handles PictureBox1.LoadCompleted With ProgressBar1 .Visible = False .Value = 0 End With End Sub Private Sub _ geoData_OperationComplete(sender As Object, _ e As Geo.GeoData.OperationCompleteEventArgs) _ Handles geoData.OperationComplete With Me .Cursor = Cursors.Default .Refresh() End With If e.OperationException IsNot Nothing Then MessageBox.Show(String.Format("An exception occurred:{0}{0}{1}", _ vbCrLf, e.OperationException.Message), _ "Program Error", MessageBoxButtons.OK, _ MessageBoxIcon.Warning) Else TextBoxInternetCity.Text = e.Locality TextBoxInternetZip.Text = e.PostalCode TextBoxInternetLat.Text = e.Latitude.ToString("f6") TextBoxInternetLon.Text = e.Longitude.ToString("f6") If e.MapData IsNot Nothing Then mapData = DirectCast(e.MapData, Geo.GeoData.MapURLs) TrackBar_ZoomLevel.Value = 10 RadioButton_Map_Aerial.Checked = True GroupBox_Maps.Enabled = True RadioButton_Map_Click(Nothing, Nothing) End If End If ButtonGetLocationFromInternet.Enabled = True End Sub End Class


    Look at the code in the button's .Click event handler. I'm not giving it any address info so it got that from my IP address.

    I'll look more into that here in a bit, but "as is", it works on this end.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 6:53 PM
  • Map stuff - great!  By the way, my interest is keen because we sometimes travel to places like Botswana or Swaziland where they do not have street addresses but sometimes we can connect to the Internet, so the only input we have would be our public IP address.  Make sense?

    Ron Chandler

    Ron,

    Would you try something please?

    Let me know what (if anything) this shows in the MessageBox:

    Option Strict On Option Explicit On Option Infer Off Imports System.IO Imports System.Net Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load Dim s As String = GetTextFromURL("http://ipinfo.io") If Not String.IsNullOrWhiteSpace(s) Then MessageBox.Show(s, "Results") End If Stop End Sub Private Function GetTextFromURL(ByVal url As String) As String Dim retVal As String = "" Try Dim request As WebRequest = WebRequest.Create(url) Using response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse) Using dataStream As Stream = response.GetResponseStream Using reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() retVal = responseFromServer End Using End Using End Using Catch ex As Exception retVal = "" End Try Return retVal End Function End Class



    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Thursday, December 24, 2015 7:42 PM
  • Got a message I can use!

    


    Ron Chandler

    Friday, December 25, 2015 12:10 AM
  • Got a message I can use!

    


    Ron Chandler

    Good then!

    Did you get a lat/lon? That's primarily what I'm hoping for.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Friday, December 25, 2015 12:28 AM
  • I tried your new code.  It works just fine with the statement:

    'geoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")'

    but the statement:

    'geoData.Start(bingAPIkey, Geo.GeoData.ImageType.Png, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height)'

    results in the following error:

    An excdeption occurred: The remote server returned an error: (400) Bad Request

    It cannot be my bingAPIkey, it must be something else.


    Ron Chandler

    Friday, December 25, 2015 1:29 AM
  • I tried your new code.  It works just fine with the statement:

    'geoData.Start(bingAPIkey, "104 Archway Circle", "Dickson", "TN", "37055")'

    but the statement:

    'geoData.Start(bingAPIkey, Geo.GeoData.ImageType.Png, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height)'

    results in the following error:

    An excdeption occurred: The remote server returned an error: (400) Bad Request

    It cannot be my bingAPIkey, it must be something else.


    Ron Chandler

    Right, that won't work on your end which is why we're trying a new approach.

    Did your test give you back the location data for latitude/longitude?

    *****

    Naomi is apparently irritated and trying to close this thread - she's voted everyone in this thread (other than me) as the proposed answerer.

    Do you want to mark them as the answerer then start another post and we'll continue there?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Friday, December 25, 2015 1:33 AM
  • Yes - returned:

    "loc:" "30.5309,-88.4999"


    Ron Chandler

    Friday, December 25, 2015 1:37 AM
  • Yes - returned:

    "loc:" "30.5309,-88.4999"


    Ron Chandler

    Use that as a string as one of the parameters then.

    By that I mean, the latitude (as a string), a comma, and the longitude (as a string).

    See if that will then return the data? If it will then that's the key to make this work on your end.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Friday, December 25, 2015 1:41 AM
  • I will start another post with a question like "find GPS coordinates based on public IP address and show map"

    Ron Chandler

    Friday, December 25, 2015 1:43 AM
  • I Input the coordinates ('geoData.Start(bingAPIkey, "30.5309", "-88.4999")' and got my location here in Mississippi back.  Now how to call with just my public IP address?

    Ron Chandler

    Friday, December 25, 2015 1:53 AM