Geolocation API with Opencage Data (NEW!)

Its been a while about searching a solution to preview the exact location name from the longitude & latitude from location sensor from device and return with complete address of your location. I want to share you this simple and new idea that I know where been searching for! Here is the project link:

https://x.thunkable.com/projects/5d7f2d051786243a5b796e42/b85809ee-77af-4ec4-bcd2-73f5eb51529d/blocks
API FROM : Opencage data (OpenCage Geocoding API Documentation)

Thank you in advance !

3 Likes

Everything works for me on Android 8.1. Only, instead of the open block, I used the block pressing the button, because the map may not be initialized at the time of opening the screen

3 Likes

Hi, @junjoseph! :wave:


This looks interesting! :smile: :+1:

Please edit the category of this topic to #thunkable-cross-tutorials :blush:


Thanks! :blush:

2 Likes

Hi junjoseph,

thanks for the post. i want to do this via mapbox i have seen that you used it to get distance. i want to use it for reverse lookup and having all the specific thing in a address separately like street name, house no. post code and location

i get this response i don’t know how to extract the data from it

could you please help me with the blocks thanks in advance

Hi, @Tijender_Singh ! :wave:

Can you please provide the .json response as text instead of image?
Also, can you please bold out the properties which you want to get?

This would help a lot :slightly_smiling_face:

Thanks! :blush:

2 Likes

thanks for your response kartik14

here is the text format
{“type”:“FeatureCollection”,“query”:[10.037273,53.568987],“features”:[{“id”:“address.4665831739750154”,“type”:“Feature”,“place_type”:[“address”],“relevance”:1,“properties”:{“accuracy”:“point”},“text”:“Eilenau”,“place_name”:“Eilenau 64, 22089 Hamburg, Germany”,“center”:[10.037214,53.568968],“geometry”:{“type”:“Point”,“coordinates”:[10.037214,53.568968]},“address”:“64”,“context”:[{“id”:“locality.12947309014235740”,“wikidata”:“Q1807”,“text”:“Eilbek”},{“id”:“postcode.9427536939672130”,“text”:“22089”},{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“locality.12947309014235740”,“type”:“Feature”,“place_type”:[“locality”],“relevance”:1,“properties”:{“wikidata”:“Q1807”},“text”:“Eilbek”,“place_name”:“Eilbek, 22089, Hamburg, Germany”,“bbox”:[10.0318294040805,53.5608598033302,10.0627037988667,53.5760205975712],“center”:[10.04556,53.56778],“geometry”:{“type”:“Point”,“coordinates”:[10.04556,53.56778]},“context”:[{“id”:“postcode.9427536939672130”,“text”:“22089”},{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“postcode.9427536939672130”,“type”:“Feature”,“place_type”:[“postcode”],“relevance”:1,“properties”:{},“text”:“22089”,“place_name”:“22089, Hamburg, Germany”,“bbox”:[10.031423,53.560813,10.062851,53.576126],“center”:[10.04,53.57],“geometry”:{“type”:“Point”,“coordinates”:[10.04,53.57]},“context”:[{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“place.10793468240398860”,“type”:“Feature”,“place_type”:[“region”,“place”],“relevance”:1,“properties”:{“short_code”:“DE-HH”,“wikidata”:“Q1055”},“text”:“Hamburg”,“place_name”:“Hamburg, Germany”,“bbox”:[8.42221516681975,53.39534,10.325959,53.9654594928706],“center”:[10,53.55],“geometry”:{“type”:“Point”,“coordinates”:[10,53.55]},“context”:[{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“country.10743216036480410”,“type”:“Feature”,“place_type”:[“country”],“relevance”:1,“properties”:{“short_code”:“de”,“wikidata”:“Q183”},“text”:“Germany”,“place_name”:“Germany”,“bbox”:[5.866003,47.270461,15.041428,55.0845576],“center”:[10,51],“geometry”:{“type”:“Point”,“coordinates”:[10,51]}}],“attribution”:“NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare.”}

{
“type”:“FeatureCollection”,
“query”:[
10.037273,
53.568987
],
“features”:[
{
“id”:“address.4665831739750154”,
“type”:“Feature”,
“place_type”:[
“address”
],
“relevance”:1,
“properties”:{
“accuracy”:“point”
},
“text”:“Eilenau”,
“place_name”:“Eilenau 64, 22089 Hamburg, Germany”,
“center”:[
10.037214,
53.568968
],
“geometry”:{
“type”:“Point”,
“coordinates”:[
10.037214,
53.568968
]
},
“address”:“64”,
“context”:[
{
“id”:“locality.12947309014235740”,
“wikidata”:“Q1807”,
“text”:“Eilbek”
},
{
“id”:“postcode.9427536939672130”,
“text”:“22089”
},
{
“id”:“place.10793468240398860”,
“short_code”:“DE-HH”,
“wikidata”:“Q1055”,
“text”:“Hamburg”
},
{
“id”:“country.10743216036480410”,
“short_code”:“de”,
“wikidata”:“Q183”,
“text”:“Germany”
}
]
},
{
“id”:“locality.12947309014235740”,
“type”:“Feature”,
“place_type”:[
“locality”
],
“relevance”:1,
“properties”:{
“wikidata”:“Q1807”
},
“text”:“Eilbek”,
“place_name”:“Eilbek, 22089, Hamburg, Germany”,
“bbox”:[
10.0318294040805,
53.5608598033302,
10.0627037988667,
53.5760205975712
],
“center”:[
10.04556,
53.56778
],
“geometry”:{
“type”:“Point”,
“coordinates”:[
10.04556,
53.56778
]
},
“context”:[
{
“id”:“postcode.9427536939672130”,
“text”:“22089”
},
{
“id”:“place.10793468240398860”,
“short_code”:“DE-HH”,
“wikidata”:“Q1055”,
“text”:“Hamburg”
},
{
“id”:“country.10743216036480410”,
“short_code”:“de”,
“wikidata”:“Q183”,
“text”:“Germany”
}
]
},
{
“id”:“postcode.9427536939672130”,
“type”:“Feature”,
“place_type”:[
“postcode”
],
“relevance”:1,
“properties”:{

     },
     "text":"22089",
     "place_name":"22089, Hamburg, Germany",
     "bbox":[ 
        10.031423,
        53.560813,
        10.062851,
        53.576126
     ],
     "center":[ 
        10.04,
        53.57
     ],
     "geometry":{ 
        "type":"Point",
        "coordinates":[ 
           10.04,
           53.57
        ]
     },
     "context":[ 
        { 
           "id":"place.10793468240398860",
           "short_code":"DE-HH",
           "wikidata":"Q1055",
           "text":"Hamburg"
        },
        { 
           "id":"country.10743216036480410",
           "short_code":"de",
           "wikidata":"Q183",
           "text":"Germany"
        }
     ]
  },
  { 
     "id":"place.10793468240398860",
     "type":"Feature",
     "place_type":[ 
        "region",
        "place"
     ],
     "relevance":1,
     "properties":{ 
        "short_code":"DE-HH",
        "wikidata":"Q1055"
     },
     "text":"Hamburg",
     "place_name":"Hamburg, Germany",
     "bbox":[ 
        8.42221516681975,
        53.39534,
        10.325959,
        53.9654594928706
     ],
     "center":[ 
        10,
        53.55
     ],
     "geometry":{ 
        "type":"Point",
        "coordinates":[ 
           10,
           53.55
        ]
     },
     "context":[ 
        { 
           "id":"country.10743216036480410",
           "short_code":"de",
           "wikidata":"Q183",
           "text":"Germany"
        }
     ]
  },
  { 
     "id":"country.10743216036480410",
     "type":"Feature",
     "place_type":[ 
        "country"
     ],
     "relevance":1,
     "properties":{ 
        "short_code":"de",
        "wikidata":"Q183"
     },
     "text":"Germany",
     "place_name":"Germany",
     "bbox":[ 
        5.866003,
        47.270461,
        15.041428,
        55.0845576
     ],
     "center":[ 
        10,
        51
     ],
     "geometry":{ 
        "type":"Point",
        "coordinates":[ 
           10,
           51
        ]
     }
  }

],
“attribution”:“NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare.”
}

hey @kartik14 please help me me know how to extract this info.

thanks in advance.

Hi,

2 Likes

Hi Actech,

Many thanks for your reply.

still not getting response

i need this info

1 Like

thanks again Actech… still not getting any value… no error no response on label5

when i do like this i get the correct data.

do you know what is the issue here

If the response is an object, the block get object from JSON is not needed. Delete block get object from JSON before response.

2 Likes

Thanks again
done that but still getting no response if i manually put it like text then i get the correct detail

What text you are in the response unit?

Label5 set Text < response ?

2 Likes

when lable 5 is set to response i get this :

{“type”:“FeatureCollection”,“query”:[10.04861,53.563669],“features”:[{“id”:“address.4255550467408700”,“type”:“Feature”,“place_type”:[“address”],“relevance”:1,“properties”:{“accuracy”:“point”},“text”:“Hasselbrookstraße”,“place_name”:“Hasselbrookstraße 98, 22089 Hamburg, Germany”,“center”:[10.048227,53.563787],“geometry”:{“type”:“Point”,“coordinates”:[10.048227,53.563787]},“address”:“98”,“context”:[{“id”:“locality.12947309014235740”,“wikidata”:“Q1807”,“text”:“Eilbek”},{“id”:“postcode.9427536939672130”,“text”:“22089”},{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“locality.12947309014235740”,“type”:“Feature”,“place_type”:[“locality”],“relevance”:1,“properties”:{“wikidata”:“Q1807”},“text”:“Eilbek”,“place_name”:“Eilbek, 22089, Hamburg, Germany”,“bbox”:[10.0318294040805,53.5608598033302,10.0627037988667,53.5760205975712],“center”:[10.04556,53.56778],“geometry”:{“type”:“Point”,“coordinates”:[10.04556,53.56778]},“context”:[{“id”:“postcode.9427536939672130”,“text”:“22089”},{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“postcode.9427536939672130”,“type”:“Feature”,“place_type”:[“postcode”],“relevance”:1,“properties”:{},“text”:“22089”,“place_name”:“22089, Hamburg, Germany”,“bbox”:[10.031423,53.560813,10.062851,53.576126],“center”:[10.04,53.57],“geometry”:{“type”:“Point”,“coordinates”:[10.04,53.57]},“context”:[{“id”:“place.10793468240398860”,“short_code”:“DE-HH”,“wikidata”:“Q1055”,“text”:“Hamburg”},{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“place.10793468240398860”,“type”:“Feature”,“place_type”:[“region”,“place”],“relevance”:1,“properties”:{“short_code”:“DE-HH”,“wikidata”:“Q1055”},“text”:“Hamburg”,“place_name”:“Hamburg, Germany”,“bbox”:[8.42221516681975,53.39534,10.325959,53.9654594928706],“center”:[10,53.55],“geometry”:{“type”:“Point”,“coordinates”:[10,53.55]},“context”:[{“id”:“country.10743216036480410”,“short_code”:“de”,“wikidata”:“Q183”,“text”:“Germany”}]},{“id”:“country.10743216036480410”,“type”:“Feature”,“place_type”:[“country”],“relevance”:1,“properties”:{“short_code”:“de”,“wikidata”:“Q183”},“text”:“Germany”,“place_name”:“Germany”,“bbox”:[5.866003,47.270461,15.041428,55.0845576],“center”:[10,51],“geometry”:{“type”:“Point”,“coordinates”:[10,51]}}],“attribution”:“NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare.”}

Well, in this case, the block get object from JSON is needed. Bring it back. Should work.

2 Likes

I was going to say this only :smile:

Thanks! :blush:

1 Like

Instead of using global variables as a function of the parameter block in my example (variable x)

1 Like

Hi, i never used it… i get only these 3 options… can you help me know how x is being created.

image