2

I would like to know if there is a way in B4A to get the geocode for a postal address and then assign it a unique number. If this can be done, please show me the coding needed to obtain the geocode and unique number.

I assume it would need to go out to a web site and get the geocode from there or use the Google Map API in some way.

Thanks.

Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152

3 Answers3

4

Once you have obtained coordinates, call the Google Geocoding API web service.

You will need to pass parameters latlng (latitude/longitude) and sensor=true to receive a result. Other parameters can be included to filter results (http://code.google.com/apis/maps/documentation/geocoding/#GeocodingRequests)

An example call would be http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

Once you get a JSON response you can use the B4A JSON library to extract the data you require

jb11
  • 557
  • 5
  • 18
  • Thanks for the response James, I clicked the link and looked through the returned results but could not find something that represents a single unique number. I will use that to get the address when I call it with the geocode. Is it possible to call maps.googleapis.com and ask it to return a single number if I give them a postal address? – Emad-ud-deen Nov 27 '11 at 12:12
  • Do you mean a single number as in a street number? Or do you mean a unique number to describe every location? I don't think such a number would exist because of the limitless number of places. If you need a unique value for each location I would suggest using the latitude and longitude as an ID – jb11 Nov 28 '11 at 23:55
  • Each postal address will have it's own lat & long. I'm looking to either convert the lat & long or the single postal address to a single number. This way I can sort all the addresses in the database table. Is there a way to call Google Geocoding to return that type of number? – Emad-ud-deen Nov 29 '11 at 01:59
1

The only solution to this problem is to concatenate the LatLon numbers together as string. You can compress the very very long result by many ways.. you can convert the string back to a number then convert the number to HEX so you can get a more shorter line.

Mosa Alimo
  • 11
  • 1
  • Welcome to StackOverflow. While trying to help OP, ask yourself how much value you have added. Can you be more clear and concise? Can you add detail? Can you format your message better. You are covering some very involved points briefly as if they were obvious and easy... – Dave Alperovich Dec 04 '13 at 03:49
0

If you are sorting them in a DB table I would suggest having an extra column that is AUTO INCREMENT and use that as the primary key. When you insert each postal address you will get a matching unique ID.

The issue of course would be the unique id would be meaningless in and of itself. So unless you want to sort by the order the records were inserted I don't see what good sorting by this number would be, but I don't know what you are doing with the info.

  • Time moves on and now a native java library exist for use with B4A which can be seen via the forum https://www.b4x.com/android/forum/threads/geocoder-library.17115/ –  Apr 10 '17 at 10:39