【问题标题】:How do I statically retrieve current LAT & LNG for instagram location?如何静态检索 Instagram 位置的当前 LAT 和 LNG?
【发布时间】:2015-03-23 20:37:53
【问题描述】:
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,但是我认为我不能使用谷歌地图 lat 和 lng 静态找到我的当前位置。

【问题讨论】:

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


    【解决方案1】:

    我认为你需要在声明它之后设置 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();
    

    【讨论】:

    • 看,这就是我认为可行的方法,但我收到消息“无法从 LocationManager 类型中对非静态方法 getLastKnownLocation(String) 进行静态引用”我无法使用 loopj 而不进行静态参考。因此,我不想完全重做我的代码,而是想通过创建静态引用以某种方式修复这几行。我不知道怎么想。
    • 嗯,我认为您应该在 onCreate 期间创建您的位置管理器,并将引用传递给此类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    相关资源
    最近更新 更多