get Baidu Address - Android Map

Android examples for Map:Address

Description

get Baidu Address

Demo Code


import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

public class Main{
    private static LocationManager locManager;
    private static Location loc;
    private static Geocoder geo;
    public static String getBaiduAddress(Context context) {
        init(context);//from   w w w .j a  va  2  s . c  o  m
        double latitude = loc.getLatitude();
        double longitude = loc.getLongitude();
        String url = String
                .format("http://api.map.baidu.com/geocoder/v2/?ak=%s&location=%s,%s&output=%s&pois=%s",
                        "C2ab471c7883b11890e509c2abb27b56", latitude,
                        longitude, "json", "0");
        try {
            return HttpUtil.getRequest(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    private static void init(Context context) {
        locManager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        loc = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        loc = loc == null ? locManager
                .getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
                : loc;
        geo = new Geocoder(context, Locale.getDefault());
    }
}

Related Tutorials