GetFromLocationName Trouble

mmieher

Active Member
Licensed User
Longtime User
Hi.

Having trouble getting the latitude and longitude from an address. Have looked at examples but I cannot get the following to compile:

Dim ad As Address
Dim myAdd() As Address
Dim gg As Geocoder
Dim aDD As String

gg.Initialize("Latitude")
aDD = "507 3rd Avenue, Oregon City, Oregon"
myAdd = gg.GetFromLocationName(aDD,1,Null)

ad = myAdd(1)

Msgbox(ad.Latitude,"")

It does not like the Null parameter for the tag, even though I see that in two other posts. It says:

Parsing code. 0.16
Compiling code. Error
Error compiling program.
Error description: Cannot assign void value.
Occurred on line: 386
myAdd = gg.GetFromLocationName(aDD,1,Null)
Word: )


I If I leave out the Null it says "too few parameters".

Anybody know what I am doing wrong?
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi,

i haved used the same routines, the only difference is:
I used it in this form without return value:
GG.GetfromLocationName(aDD,1,Null)
In the location string i use an CRLF between street adress and the rest... But i dont know, if it makes a difference.
Greetings
Reinhard
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

Having trouble getting the latitude and longitude from an address. Have looked at examples but I cannot get the following to compile:

Dim ad As Address
Dim myAdd() As Address
Dim gg As Geocoder
Dim aDD As String

gg.Initialize("Latitude")
aDD = "507 3rd Avenue, Oregon City, Oregon"
myAdd = gg.GetFromLocationName(aDD,1,Null)

ad = myAdd(1)

Msgbox(ad.Latitude,"")

It does not like the Null parameter for the tag, even though I see that in two other posts. It says:

Parsing code. 0.16
Compiling code. Error
Error compiling program.
Error description: Cannot assign void value.
Occurred on line: 386
myAdd = gg.GetFromLocationName(aDD,1,Null)
Word: )


I If I leave out the Null it says "too few parameters".

Anybody know what I am doing wrong?

B4X:
myAdd = gg.GetFromLocationName(aDD,1,Null)

gg.GetFromLocationName(aDD,1,Null) returns 'void' as a value - assigning void to myAdd (an Address object) causes the error you posted. The error is not related to the Null parameter passed as the 'Tag' value.

You should instead use:

B4X:
gg.GetFromLocationName(aDD,1,Null)

And create a Sub that handles the GeocodeDone event when it is raised.
This event will be raised after calling GetFromLocationName, once the device has queried the online geocoder service and processed the query result.

B4X:
Sub Latitude_GeocodeDone(Results() As Address, Tag As Object)
 ' here you can process the Results (Array of Address objects)
End Sub

The event handling Sub name uses Latitude as that is the EventName parameter you passed to the Geocoder Initialize method:

B4X:
gg.Initialize("Latitude")

Be careful if you copy Geocoder examples from the forum, the original version of the Geocoder library did not work asynchronously. It looks as though you have tried to use code that was written for the previous version of Geocoder not the new version.
More info here: http://www.b4x.com/forum/additional...ates/17115-geocoder-library-3.html#post138637.

Martin.
 
Last edited:
Upvote 0
Top