Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GET street address by lat and lng 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
My code:
Private Sub APRI_LAT_LNG()

STRADA = LAT & "," & LNG

Me.WebBrowser1.Visible = True
Me.Text1.SetFocus

Me.WebBrowser1.Navigate " & STRADA & "/17?mapSize=640,480&pp=" & STRADA & ";8&mapLayer=Basemap,Buildings&key=" & BINGKEY

Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

Me.CZOOM.Enabled = True

Me.WebBrowser1.Document.body.Style.border = "none"
Me.WebBrowser1.Document.body.Scroll = "no"
Me.WebBrowser1.Document.body.setAttribute "scroll", "no"

Me.Text1.SetFocus

End Sub

possible to return in MyVarStreet the name of the nearest street, the lat and lng value?

use for test:

lat=40.674700
lng=14.510800

is a street based city=NAPOLI>countryPIMONTE>zipcode>80050
 
You can certainly get what Bing calls 'location data; from a lat and long - but not sure if location data contains street names.
 
strongm, is important, in other case...
 

for strong...

with
return:

<Response xmlns:xsd=" xmlns:xsi=" xmlns="<Copyright>Copyright © 2022 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
<BrandLogoUri><StatusCode>200</StatusCode>
<StatusDescription>OK</StatusDescription>
<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
<TraceId>7a581d502a7b45c09ec473f7bbd7ab1c|DU00002782|0.0.0.1</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<Location>
<Name>Frazione Morgnano 25, 06049 Spoleto Perugia</Name>
<Point>
<Latitude>42.778046</Latitude>
<Longitude>12.6879169</Longitude>
</Point>
<BoundingBox>
<SouthLatitude>42.774183282429327</SouthLatitude>
<WestLongitude>12.680900499518883</WestLongitude>
<NorthLatitude>42.78190871757068</NorthLatitude>
<EastLongitude>12.694933300481116</EastLongitude>
</BoundingBox>
<EntityType>Address</EntityType>
<Address>
<AddressLine>Frazione Morgnano 25</AddressLine>

<AdminDistrict>Umbria</AdminDistrict>
<AdminDistrict2>Perugia</AdminDistrict2>
<CountryRegion>Italy</CountryRegion>
<FormattedAddress>Frazione Morgnano 25, 06049 Spoleto Perugia</FormattedAddress>
<Locality>Spoleto</Locality>
<PostalCode>06049</PostalCode>
</Address>

<Confidence>High</Confidence>
<MatchCode>Good</MatchCode>
<GeocodePoint>
<Latitude>42.778046</Latitude>
<Longitude>12.6879169</Longitude>
<CalculationMethod>Rooftop</CalculationMethod>
<UsageType>Display</UsageType>
</GeocodePoint>
</Location>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>

how to get the bold info?
 
Why do you want all of the bold text when your original query relates to simply getting the street address?

Now, if it is just the address line you need, then some simple XML-extracting code will do the trick. The following assumes you have a form with a textbox containing your good, well-formed XML response

Code:
[COLOR=blue]Option Explicit

Private Sub Command1_Click()
    MsgBox GetAddressLine(Text1.Text)
End Sub

Public Function GetAddressLine(myXMLString As String) As String
    Dim objXML As New MSXML2.DOMDocument
    
    If objXML.LoadXML(myXMLString) Then
        [COLOR=green]' Get first match. And remember that XML is case-sensitive[/color]
        GetAddressLine = objXML.SelectSingleNode("//AddressLine").Text
    Else
        [COLOR=green]' oops - XML failed to load[/color]
    End If
End Function[/color]

(oh, and by not surrounding your examples with TGML tags that prevent parsing, your links get modified for display, e.g we see


versus the same link surrounded by e.g. Pre tags:

[pre][/pre]
)
 
TKS STRONGM,
but wath is the parameter in bold, MsgBox GetAddressLine(Text1.Text)
 
strongm
i use

.....

XMLQUERY = " & LAT & "," & LNG & "?o=xml&C=IT&key=" & BINGKEY

With CreateObject("MSXML2.XMLHTTP")

.Open "GET", XMLQUERY, False
.send

Do While myXML.ReadyState <> READYSTATE_COMPLETE
Sleep (100)
Loop

myXML.loadXML .responseText 'raw xml
Set nodes = myXML.selectNodes("//*")

MsgBox GetAddressLine(?????)

.....
 
So, in your code (or more accurately my code, since it looks to be an extract from my example in thread222-1807492 of 18 months ago) myXML is the same thing as objXML - an MSXML2.DOMDocument object with XML loaded

Sop you don't need my function (which assumed you had TEXT that you wanted to work with as per your post 2 Jun 22), just:

[tt]MsgBox objXML.SelectSingleNode("//AddressLine").Text[/tt]

By the way - just a reminder: my posts here are NOT production code; they are examples of possible solutions. They do not have error checking, bounds checking, or even include simple checks for valid return values. The idea is that you take the example and figure out how to best use it in your code. I point this out because if the XML response from Bing does not have AddressLine as a node in the returned XML both my original function and the above code will error - and, sorry Sal21, I have no intention of spending my time talking you through error handling.
 
sorry strong i'm busy (inFamily)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top