如何将FusedClient提供的纬度和经度发送到Volley中的getParams
方法,如果两者都超出范围?
这是我从FusedClient获取位置的方法:
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getActivity());
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setFastestInterval(2000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) {
return;
}
for (Location location : locationResult.getLocations()) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
}
}
};
这是我使用Volley将POST
参数发送到远程服务器的方式:
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG,"Response: " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG,"That didn't work!");
}
}) {
@Override
public Map getParams() {
Map params = new HashMap();
//How to put latitude and longitude in this map?
return params;
}
};
答案 0 :(得分:0)
几件事:
getParams
和onLocationResult
中进行访问。static/class
成员。 将onLocationResult
中的地图填充为
myStaticHashMap.put("lat_" + myStaticInteger, location.getLatitude());
myStaticHashMap.put("lang_" + myStaticInteger, location.getLongitude());
++myStaticInteger;
getParams
中,返回myStaticHashMap
。synchronise
对静态成员vars的访问。