B4A Library Geocoder library

Geocoder library

The Geocoder library enables you to geocode coordinates and reverse geocode addresses.

The library adds two new Objects to the IDE:

Version: 2.1
  • Address
    Methods:
    • HasLatitude As Boolean
      Returns True if a latitude has been assigned to this Address, False otherwise.
    • HasLongitude As Boolean
      Returns True if a longitude has been assigned to this Address, False otherwise.
    • IsInitialized As Boolean
    Properties:
    • AddressLines As List [read only]
      Returns a List of Strings which are the address lines of the Address.
    • AdminArea As String [read only]
      Returns the administrative area name of the Address.
      For example, "CA", or Null if it is unknown.
    • CountryCode As String [read only]
      Returns the country code of the Address.
      For example "US", or Null if it is unknown.
    • CountryName As String [read only]
      Returns the localized country name of the Address.
      For example "Iceland", or Null if it is unknown.
    • FeatureName As String [read only]
      Returns the feature name of the Address.
      For example, "Golden Gate Bridge", or Null if it is unknown.
    • Latitude As Double [read only]
      Returns the latitude of the Address if known.
    • Locality As String [read only]
      Returns the locality of the Address.
      For example "Mountain View", or Null if it is unknown.
    • Longitude As Double [read only]
      Returns the longitude of the Address if known.
    • Phone As String [read only]
      Returns the phone number of the Address if known, or Null if it is unknown.
    • PostalCode As String [read only]
      Returns the postal code of the Address.
      For example "94110", or Null if it is unknown.
    • Premises As String [read only]
      Returns the premises of the Address, or Null if it is unknown.
    • SubAdminArea As String [read only]
      Returns the sub-administrative area name of the Address.
      For example, "Santa Clara County", or Null if it is unknown.
    • SubLocality As String [read only]
      Returns the sub-locality of the Address, or Null if it is unknown.
    • SubThoroughfare As String [read only]
      Returns the sub-thoroughfare name of the Address, or Null if it is unknown.
    • Thoroughfare As String [read only]
      Returns the thoroughfare name of the Address.
      For example, "1600 Ampitheater Parkway", or Null if it is unknown.
    • Url As String [read only]
      Returns the public URL for the Address, or Null if it is unknown.
  • Geocoder
    Events:
    • GeocodeDone (Addresses() As Address, Tag As Object)
    Methods:
    • GetFromLocation (Latitude As Double, Longitude As Double, MaxResults As Int, Tag As Object)
      Gets an Array of Address objects that describe the area immediately surrounding the given Latitude and Longitude.
      The Array of Address objects is passed back to B4A in the GeocodeDone event along with the Tag Object.
      Tag is not used by this method, it is simply a means by which you can associate an identifying Object with this task.
    • GetFromLocationName (LocationName As String, MaxResults As Int, Tag As Object)
      Gets an Array of Address objects that describe the named location.
      LocationName may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc...
      The Array of Address objects is passed back to B4A in the GeocodeDone event along with the Tag Object.
      Tag is not used by this method, it is simply a means by which you can associate an identifying Object with this task.
    • GetFromLocationName2 (LocationName As String, MaxResults As Int, LowerLeftLatitude As Double, LowerLeftLongitude As Double, UpperRightLatitude As Double, UpperRightLongitude As Double, Tag As Object)
      Returns an array of Addresses that are known to describe the named location within the geographical bounds.
      LocationName may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc..
      The Array of Address objects is passed back to B4A in the GeocodeDone event along with the Tag Object.
      Tag is not used by this method, it is simply a means by which you can associate an identifying Object with this task.
    • Initialize (EventName As String)
      Initialize the Geocoder object with the device's system Locale.
    • Initialize2 (EventName As String, Language As String)
      Initialize the Geocoder object with a Locale based on Language.
    • Initialize3 (EventName As String, Language As String, Country As String)
      Initialize the Geocoder object with a Locale based on Language and Country.
    • IsInitialized As Boolean
    • IsPresent As Boolean
      Returns true if the Geocoder methods GetFromLocation and GetFromLocationName etc are implemented.
      Lack of network connectivity may still cause these methods to return null or empty lists.

If any of the three Geocoder methods Get??? fail then the GeocodeDone event will simply be passed an array of zero Address objects.
Any exceptions will be caught and sent to the log.

Library files and demo code attached.

Martin.
 

Attachments

  • Geocoder_v2_10.zip
    21.6 KB · Views: 2,018
Last edited:

juventino883

Member
Licensed User
Longtime User
Hi Warwound The geocoder example is not working in my phone everitime I get "No results found" or "No latitude and longitude found for the LocationName" I use a huawei ascend mate 7. what can i do?
 

warwound

Expert
Licensed User
Longtime User
Hi Warwound The geocoder example is not working in my phone everitime I get "No results found" or "No latitude and longitude found for the LocationName" I use a huawei ascend mate 7. what can i do?

Try rebooting the device - does it now work?
 

juventino883

Member
Licensed User
Longtime User
Hi, Warwound I reboot the device and now work only the get from location name part (geocoding) but I cant make the reverse geocoding, why do you think is this problem? and why I need to reboot my device?
 

juventino883

Member
Licensed User
Longtime User
warwound now is all working!!, one question, this geocoder lib has limitations? I ask because for example the geocoder api from Google only allows 2500 requests per 24 hour period and 5 requests per second.

regards.
 

trueboss323

Active Member
Licensed User
Longtime User
The reverse geocode function is not working for some devices. I tested and it works on a Sony Xperia M2 , but on a ZTE Valet it's not able to get a location. Even though both of these devices have GPS capabilities. What seems to be the problem?
 

peacemaker

Expert
Licensed User
Longtime User
The reverse geocode function is not working for some devices. I tested and it works on a Sony Xperia M2 , but on a ZTE Valet it's not able to get a location. Even though both of these devices have GPS capabilities. What seems to be the problem?
Are other Google services\apps installed ?
 

Indy

Active Member
Licensed User
Longtime User
This is really a very useful library - Thank you!

A quick question though - I was wondering, does the Address collection just have the street name only? I get back the House number and street but, for my app I just need the street. If not I'll just strip all characters up to the first space.

Thanks.
 

warwound

Expert
Licensed User
Longtime User
Hi,
there should be an overload method getFromLocationName with bounding box parameters.
http://developer.android.com/reference/android/location/Geocoder.html#getFromLocationName
Is there a chance of adding this method to your nice lib?


Thanks

Can you test the attached update?
I've added the method:

GetFromLocationName2 (LocationName As String, MaxResults As Int, LowerLeftLatitude As Double, LowerLeftLongitude As Double, UpperRightLatitude As Double, UpperRightLongitude As Double, Tag As Object)

Also added:

IsPresent As Boolean
Returns true if the Geocoder methods GetFromLocation and GetFromLocationName etc are implemented.
Lack of network connectivity may still cause these methods to return null or empty lists.
 

warwound

Expert
Licensed User
Longtime User
Geocoder library updated to version 2.10

See post #94 for more info.
Version 2.10 is attached to the first post in this thread.
 

JAVIERGARCIA

Member
Licensed User
Longtime User
Hello, very good code and libraries;
there is one thing that is not good as done;
as you might be assigned to different variables results resultslist the designer;

variable_1 = adress1
variable_2 = adress2
variable_3 = adress3

thanks
 

melvin2345

Member
Licensed User
Longtime User
I'm getting proper latitude and longitude (confirmed with google maps api), but getFromLocation always returns 0 results (google maps api returns a bunch). Anyone else experience this?
 

quique

Member
Licensed User
Longtime User
Hi Martin! Thank you for this library. I just tested it for a project I am trying to accomplish, and it works fine !!

On a side note, in my country, when consulted by address, it returns a Lat and Long about a block away :( Of course it is not the library's fault, but only google's faulty data. Same thing happens when I search for my address, in maps.google.com :( ... while Bing map (Microsoft) returns my home with pinpoint accuracy ... grrr google !!

I am telling my experience in order for other coders to be aware that google's address - geoposition accuracy may NOT be correct in some countries / instances :(
 
Top