Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Address from Lat/Long in Android or REST

I am working with an Android app which interacting with a REST web service. We have a function in the phone in order to choose a location in Google native map, and send to the server.

For some reason we need to get the address for that point in the website to print-out.

If we get the address from Latitude and Longtitude in the phone using Geocoder and send it to the REST, we need to consume some memory, data and bandwidth in the phone.

If we do it in the REST, since it should be done for many users who are using the application, the process could be time-consuming. (this is what our REST developer believe)

Can you help me with your opinions? which idea is better and why?

like image 685
Ali Avatar asked Oct 21 '22 07:10

Ali


2 Answers

What you are doing is called "reverse geocoding" (https://developers.google.com/maps/documentation/geocoding/?hl=fr#ReverseGeocoding)

About you question: I understood that you reverse geocode some users' positions and that the genrated addresses will be used by many other users.

Knowing that : 1. reverse geoding is costly 2. the obtained address will be used by many users 3. each user will use many of those addresses Then you should do it server side and put all the addresses in one message. If you can limit the number of addresses to the only ones useful, it will be better (probably the ones near you, but depends on your app features)

Important: When on mobile, what's critical for performances isn't that the amount of data transfered rather than the number of messages: bandwidth is nice but lag is terrible. So in your server API, avoid atomic operation and aggregate as much as it makes sense!

like image 65
Pr Shadoko Avatar answered Oct 27 '22 11:10

Pr Shadoko


please use this function

String getAddress(Double lat,Double lon) { String address = "";

    GeoPoint point = new GeoPoint((int) (lat * 1E6),
            (int) (lon * 1E6));

    Geocoder geoCoder = new Geocoder(mContext, Locale.getDefault());
    try {
        List<Address> addresses = geoCoder.getFromLocation(
                point.getLatitudeE6() / 1E6, point.getLongitudeE6() / 1E6,
                1);

        if (addresses.size() > 0) {
            for (int index = 0; index < addresses.get(0)
                    .getMaxAddressLineIndex(); index++)
                address += addresses.get(0).getAddressLine(index) + " ";
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

    return address;
}
like image 23
Ashish Agrawal Avatar answered Oct 27 '22 11:10

Ashish Agrawal