Android Question Library to return lat & lon of postal address

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Is there a B4A library that will allow me to send it a postal address and have it return the latitude and longitude for that address?

Thanks.
 

MarcoRome

Expert
Licensed User
Longtime User
You can use Google API Maps.
Example: if you have this Address: "rivadavia 3250,Ciudad de BuenosAires, Argentina"

You can set this:

B4X:
    Dim Job As HttpJob
Dim found as string = "rivadavia 3250,Ciudad de BuenosAires, Argentina"
Job.Initialize("foundcoordinate", Me)
Job.Download($"http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=${found}"$)

and you will be this result in json, where you can found coordinate, etc.

B4X:
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=rivadavia%203250,%20Ciudad%20de%20Buenos%20Aires,%20Argentina

{
"results" : [
{
"address_components" : [
{
"long_name" : "3250",
"short_name" : "3250",
"types" : [ "street_number" ]
},
{
"long_name" : "Avenida Rivadavia",
"short_name" : "Av. Rivadavia",
"types" : [ "route" ]
},
{
"long_name" : "Balvanera",
"short_name" : "Balvanera",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Comuna 3",
"short_name" : "Comuna 3",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Ciudad Autónoma de Buenos Aires",
"short_name" : "CABA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Argentina",
"short_name" : "AR",
"types" : [ "country", "political" ]
},
{
"long_name" : "C1203AAR",
"short_name" : "C1203AAR",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Av. Rivadavia 3250, C1203AAR CABA, Argentina",
"geometry" : {
"location" : {
"lat" : -34.610687,
"lng" : -58.41248100000001
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : -34.6093380197085,
"lng" : -58.4111320197085
},
"southwest" : {
"lat" : -34.61203598029149,
"lng" : -58.41382998029151
}
}
},
"partial_match" : true,
"place_id" : "ChIJIWt6EPTKvJURmCUieVT6zRw",
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "3250",
"short_name" : "3250",
"types" : [ "street_number" ]
},
{
"long_name" : "Rivadavia",
"short_name" : "Rivadavia",
"types" : [ "route" ]
},
{
"long_name" : "San Martin",
"short_name" : "San Martin",
"types" : [ "locality", "political" ]
},
{
"long_name" : "General San Martin",
"short_name" : "Gral San Martin",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Buenos Aires",
"short_name" : "Buenos Aires",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Argentina",
"short_name" : "AR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Rivadavia 3250, San Martin, Buenos Aires, Argentina",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -34.5708311,
"lng" : -58.53745230000001
},
"southwest" : {
"lat" : -34.5708422,
"lng" : -58.53746539999999
}
},
"location" : {
"lat" : -34.5708311,
"lng" : -58.53746539999999
},
"location_type" : "RANGE_INTERPOLATED",
"viewport" : {
"northeast" : {
"lat" : -34.5694876697085,
"lng" : -58.5361098697085
},
"southwest" : {
"lat" : -34.5721856302915,
"lng" : -58.53880783029151
}
}
},
"partial_match" : true,
"place_id" : "EjNSaXZhZGF2aWEgMzI1MCwgU2FuIE1hcnRpbiwgQnVlbm9zIEFpcmVzLCBBcmdlbnRpbmE",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
You can use Google API Maps.
Example: if you have this Address: "rivadavia 3250,Ciudad de BuenosAires, Argentina"

You can set this:

B4X:
    Dim Job As HttpJob
Dim found as string = "rivadavia 3250,Ciudad de BuenosAires, Argentina"
Job.Initialize("foundcoordinate", Me)
Job.Download($"http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=${found}"$)

and you will be this result in json, where you can found coordinate, etc.

B4X:
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=rivadavia%203250,%20Ciudad%20de%20Buenos%20Aires,%20Argentina
Thanks for the coding. I will see if I can find a json tutorial on the B4A web site.
 
Upvote 0
Top