如何静态检索当前的LAT&液化天然气的Instagram位置?

时间:2015-03-23 20:37:54

标签: java google-maps latitude-longitude android-maps-v2 instagram-api

private static final String CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static final String PARAM_NAME_CLIENT_ID = "client_id";
private final int COUNT = 100;
private static final String instagramAPI = "https://api.instagram.com/v1/media/search?";
private static LatLng mLatLng;
private static final String LAT = "lat=";
private static final String LNG = "&lng=";
private static final String distance = "&distance=";
static Location location;
GoogleMap map;
private Context context;
static double latitude;
static double longitude;
public  InstagramPhotosClient(double latitude, double longitude) {


}


LocationManager service = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, false);
Location location1 = service.getLastKnownLocation(provider);
LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());

public static String getRequestCacheKey() {
    return String.valueOf(latitude) + String.valueOf(longitude);
}
private static AsyncHttpClient client = new AsyncHttpClient();

public static void getPopularPhotos(AsyncHttpResponseHandler handler) {
    String url = instagramAPI + LAT + latitude + LNG
            + longitude;
    RequestParams params = new RequestParams();
    params.put(PARAM_NAME_CLIENT_ID, CLIENT_ID);
    client.get(url, params, handler);
}

}

我必须使用loopj http jsonhttpresponsehandler静态引用另一个类中的url,但是我不认为我可以使用google maps lat和lng静态地找到我当前的位置。

1 个答案:

答案 0 :(得分:0)

我认为您需要在声明之后设置LocationManager,并且在获得getLastKnownLocation的经度和纬度之前。这就是我接近它的方式:

    LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, new LocationListener() {
    @Override
    public void onStatusChanged(String s, int i, Bundle bundle) {}
    @Override
    public void onProviderEnabled(String s) {}
    @Override
    public void onProviderDisabled(String s) {}
    @Override
    public void onLocationChanged(final Location location) {}
});
Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
double longitude = myLocation.getLongitude();
double latitude = myLocation.getLatitude();