I have problems with the geocoder library that in vb4 version 7 does not work.
then I found the option to take the data directly from google like this:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-33.453454,-70.562686
I try like this
I use this code in b4a
but it marks me the following error:
java.lang.RuntimeException: JSON Array expected.
thank you ideas
then I found the option to take the data directly from google like this:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-33.453454,-70.562686
I try like this
B4X:
{
"results" : [
{
"address_components" : [
{
"long_name" : "6500",
"short_name" : "6500",
"types" : [ "street_number" ]
},
{
"long_name" : "José Bordes",
"short_name" : "José Bordes",
"types" : [ "route" ]
},
{
"long_name" : "La Reina",
"short_name" : "La Reina",
"types" : [ "locality", "political" ]
},
{
"long_name" : "La Reina",
"short_name" : "La Reina",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "José Bordes 6500, La Reina, Región Metropolitana, Chile",
"geometry" : {
"location" : {
"lat" : -33.4534543,
"lng" : -70.56268559999999
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : -33.4521053197085,
"lng" : -70.56133661970848
},
"southwest" : {
"lat" : -33.4548032802915,
"lng" : -70.5640345802915
}
}
},
"place_id" : "ChIJgUxC_DfOYpYRpuAD4QOfAaE",
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "La Reina",
"short_name" : "La Reina",
"types" : [ "locality", "political" ]
},
{
"long_name" : "La Reina",
"short_name" : "La Reina",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "La Reina, Región Metropolitana, Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -33.428959,
"lng" : -70.51125279999999
},
"southwest" : {
"lat" : -33.4655568,
"lng" : -70.58451649999999
}
},
"location" : {
"lat" : -33.4411269,
"lng" : -70.53405909999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -33.428959,
"lng" : -70.51125279999999
},
"southwest" : {
"lat" : -33.4655568,
"lng" : -70.58451649999999
}
}
},
"place_id" : "ChIJFaFzoWrOYpYRIsmz7XCo6hQ",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "colloquial_area", "locality", "political" ]
},
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Santiago, Región Metropolitana, Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -33.2713874,
"lng" : -70.42678069999999
},
"southwest" : {
"lat" : -33.6741885,
"lng" : -70.8328819
}
},
"location" : {
"lat" : -33.4488897,
"lng" : -70.66926549999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -33.2713874,
"lng" : -70.42678069999999
},
"southwest" : {
"lat" : -33.6741885,
"lng" : -70.8328819
}
}
},
"place_id" : "ChIJL68lBEHFYpYRMQkPQDzVdYQ",
"types" : [ "colloquial_area", "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "La Reina",
"short_name" : "La Reina",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "La Reina, Región Metropolitana, Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -33.428959,
"lng" : -70.502416
},
"southwest" : {
"lat" : -33.4655568,
"lng" : -70.58451649999999
}
},
"location" : {
"lat" : -33.45,
"lng" : -70.55
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -33.428959,
"lng" : -70.502416
},
"southwest" : {
"lat" : -33.4655568,
"lng" : -70.58451649999999
}
}
},
"place_id" : "ChIJqY6OmnLOYpYRA-kAssT-Lc8",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"address_components" : [
{
"long_name" : "Santiago",
"short_name" : "Santiago",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Santiago, Región Metropolitana, Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -33.1025363,
"lng" : -70.17483899999999
},
"southwest" : {
"lat" : -33.62800259999999,
"lng" : -70.9577496
}
},
"location" : {
"lat" : -33.45,
"lng" : -70.66669999999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -33.1025363,
"lng" : -70.17483899999999
},
"southwest" : {
"lat" : -33.62800259999999,
"lng" : -70.9577496
}
}
},
"place_id" : "ChIJlVV_vxvJYpYRziXz-KE8chY",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Región Metropolitana",
"short_name" : "Región Metropolitana",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Región Metropolitana, Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -32.919451,
"lng" : -69.7689943
},
"southwest" : {
"lat" : -34.2878148,
"lng" : -71.7088102
}
},
"location" : {
"lat" : -33.4375545,
"lng" : -70.6504896
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -32.919451,
"lng" : -69.7689943
},
"southwest" : {
"lat" : -34.2878148,
"lng" : -71.7088102
}
}
},
"place_id" : "ChIJUR74fWpvYpYR2oNLRG3CzWA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "Chile",
"short_name" : "CL",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chile",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -17.4983293,
"lng" : -66.3327
},
"southwest" : {
"lat" : -56.1455,
"lng" : -110.0281
}
},
"location" : {
"lat" : -35.675147,
"lng" : -71.542969
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -17.4983293,
"lng" : -66.3327
},
"southwest" : {
"lat" : -56.1455,
"lng" : -110.0281
}
}
},
"place_id" : "ChIJL68lBEHFYpYRHbkCERPhBQU",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
I use this code in b4a
B4X:
Sub JobDone(Job As HttpJob)
Try
Dim m As Map
Dim respuesta,id,query,comentario,fecha,hora,iden_reporte,iden_reporte1,duplicado,tduplicado As String
m.Initialize()
Log("entramos....."&Job.Success)
Log("mesaje "&Job.ErrorMessage)
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Log("NOMBRE....."&Job.JobName)
Select Job.JobName
Case "geocoder"
Log("entro")
Dim tipo_i As List
tipo_i= parser.NextArray 'returns a list with maps
'For i = 0 To tipo_i.Size - 1
Dim m As Map
m = tipo_i.Get(0)
respuesta= m.Get("long_name")
Log("xxx"&respuesta)
m.Clear
'Next
End Select
Else
End If
Job.Release
Catch
'Msgbox("Error , si continúa reinicié el teléfono","Error")
Log(LastException.Message)
End Try
End Sub
but it marks me the following error:
java.lang.RuntimeException: JSON Array expected.
thank you ideas