Android Question Get coordinates from address with Bing

HARRY

Active Member
Licensed User
Longtime User
Hi,

In a program I have to show a Bing map in an ImageView with an address as starting point
I try to get the coordinates as follows:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("ConnectionForm")
    WEBView1.Initialize("WEBReturn")
    Activity.AddView(WEBView1, 0dip, 0dip, 540dip, 960dip)
    BingMapsKey="vvvvvvvvvvvvvvvvvvvvvvvv"
    URLStr1="http://dev.virtualearth.net/REST/v1/Locations?countryRegion=nl&locality=" & Main.city & "&addressLine=" & Main.Street & "&key=" & BingMapsKey
    'URLStr2 ="http://dev.virtualearth.net/REST/v1/Imagery/Map/" & MapType & "/" & POI.ActiveLat & "," & POI.ActiveLon & "/" & ZoomLevel & "?pp= " & POI.ActiveLat & "," & POI.ActiveLon & ";;1" & "&mapSize=360,640&dcl=1&key="& BingMapsKey      
    WEBView1.LoadUrl(URLStr1)
End Sub

This works more or less: as feedback I get some 1 K of data which includes the coordinates. This information is printed in the WEBView. I expected it in WEBReturn. The problem is that I have no idea how I can approach that data to extract the coordinates. Probably very simple, if you know it.
Please some help,
Harry
 
Last edited:

Beja

Expert
Licensed User
Longtime User
If the data returned is json then parsing it should be straightforward, you can even write your own routine
to extract just the coordinates.
What kind of data your are receiving?
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Hi Beja,

Parsing is not difficult, but I cannot get access to the data; there is no function to get the text written in the WebView; that is my problem. The data starts with {"authentication Result Code...Stuff about Copyright ..... several times the address and the coordinates .... .,etc. With some string operations it is simple to extract the coordinates, provided that I have access to the data.

HARRY
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
If the coordinates are included in the 1k data you are receiving, then what's the problem? sorry I am not following.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I think now I understand that you did not already captured the text..
If this is the case then you can use the Document object to get the "Body" of the web page, which should contain
JSON. then process JSON.
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
"If this is the case then you can use the Document object to get the "Body" of the web page, which should contain
JSON. then process JSON." How??

Harry
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
Harry,
Instead of using a webview, why don't you use HttpUtils2.GetString(URLStr1) to get the string to be parsed?

This may make things easier.

Douglas
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Hi Douglas,

For me the threads on HttpUtils are so confusing that I do not manage to realize a simple thing like GetString. Should I use httpRequest, httpResponse, httpJob, httpClient??? It cannot be complicated, as downloading a map, when the coordinates are known, is just one statement. Could you please make a short, but complete sample for me with declarations?

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Hi Douglas,

An example is no longer necessary. After reading carefully , again and again, I found how to use HttpUtils in the correct way. Everything now works fine.

Thanks for your support.

Harry
 
Upvote 0
Top