extract adresse from google map ?

Post your questions and help other users.

Moderator: Martin

joeko
Posts: 34
Joined: 17 Jan 2017 19:21

Re: extract adresse from google map ?

Post by joeko » 24 Jun 2019 12:58

hmm, all fine now but how i create a new variable with blank space between road and house_number ?

address = (road) + (house_number);

result is street1 and not street 1

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: extract adresse from google map ?

Post by Desmanto » 24 Jun 2019 18:22

If you check the result of the json in debug dialog, then choose to show it in json view, you will see something like this.

Code: Select all

[{
  "place_id": 79652320,
  "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
  "osm_type": "way",
  "osm_id": 23384770,
  "boundingbox": [
    "53.5868484",
    "53.5878464",
    "10.0977657",
    "10.099514"
  ],
  "lat": "53.58736045",
  "lon": "10.0985517127999",
  "display_name": "toom Baumarkt, 31,33, Am Stadtrand, Wandsbek, Hinschenfelde, Hamburg, 22047, Deutschland",
  "class": "shop",
  "type": "doityourself",
  "importance": 0.21100000000000002,
  "icon": "https://nominatim.openstreetmap.org/images/mapicons/shopping_diy.p.20.png",
  "address": {
    "doityourself": "toom Baumarkt",
    "house_number": "31,33",
    "road": "Am Stadtrand",
    "suburb": "Wandsbek",
    "city_district": "Wandsbek",
    "hamlet": "Hinschenfelde",
    "state": "Hamburg",
    "postcode": "22047",
    "country": "Deutschland",
    "country_code": "de"
  }
}]
It is easier to know the hierarchy now. So if we parse it now, it becomes

Code: Select all

road = js[0]["address"]["road"];
house_number = js[0]["address"]["house_number"];
city_district = js[0]["address"]["city_district"];
Then if we want to add some space, you can add string with space in between, or just use inline variable.

Code: Select all

address = road + " " + house_number + ", " + city_district ;
address = "{road} {house_number}, {city_district}";
Both give the same result, Am Stadtrand 31,33, Wandsbek
I prefer the + method when the variable is not final, I might append something later, or just for the purpose to see the variable easier.
I prefer the inline method when the variable is final, the address is ready to be shown in some display (example toast message or notification). Because using inline variable, makes it a bit difficult to spot the variable now, as the coloring is green and inside string.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply