Aurelian Cotuna
Aurelian Cotuna

Reputation: 3081

Geocoding slowing down everything?

I have the following problem: I wrote a function to determine the exact location of a street passed as a string parameter:

private GeoPoint LocationToGeoPointParser(String address) throws IOException
    {
        Geocoder geoCoder = new Geocoder(this.context,Locale.ENGLISH);
    List<Address> addr = null;
    addr =  geoCoder.getFromLocationName(address, 1);
    double la = addr.get(0).getLatitude();
    double lo = addr.get(0).getLongitude();

    Double longitude = addr.get(0).getLongitude()*1E6;
    Double latitude = addr.get(0).getLatitude()*1E6;
    return new GeoPoint(latitude.intValue(),longitude.intValue());
    //return new GeoPoint(73,32);
}

If I use the function this way, when the map is loaded everything is working extremely slow. If i comment the geocoding code and use return new GeoPoint(73,32), it is working normally. Can somebody explain me why geocoding slow my application down? Thanks! :)

Upvotes: 2

Views: 1611

Answers (2)

Pratik
Pratik

Reputation: 30855

The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform.

Use the Thread like Handler or AsyncTask etc to will call background then change the UI

Upvotes: 2

filip-fku
filip-fku

Reputation: 3265

I haven't used the Android APIs but I imagine that geocoding will call out to a google web service of some sort which does the geocoding and returns the result. Since that involves network communications, and the getFromLocationName() method seems to be blocking, it is not unreasonable to experience delays, perhaps even more so from a mobile internet connection. If you call your method in quick succession, there would be even more room for delay..

Of course, this is assuming that I am correct and that geocoding is done on a server somewhere..

Upvotes: 0

Related Questions