json URL에서 나에게 가까이있는 장소를 얻으려고하고 있지만 가장 가까운 장소를 차지할 수 있기 때문에 내 위치를 얻은 후에 만이 주소를 사용할 수 있습니다. 이렇게하면 onLocationChanged 내에서 위도와 경도를 얻는 메서드를 호출합니다.내 위치가 변경 될 때 JSon에서 위치 가져 오기
GoogleMap mGoogleMap;
MapView mapFrag;
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
public void onLocationChanged(Location location)
{
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
loadJson(location.getLatitude(),location.getLongitude());
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(11));
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
문제는 내가 RequestQueue 및 StringRequest의 innerclass의 Response.Listener의 방법 onResonse에 도달하지 않습니다를 사용하여 JSON 배열을 위해 노력하고있는 방법이다. 그리고지도에 표식을 추가하는 것은이 메서드 내부에 있습니다.
private void loadJson(double lat, double longit){
lat = -22.950491;
longit= -43.181609;
// Store values at the time of the login attempt.
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://MyJsonURL";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
List<Places> arrayList = new ArrayList<Places>();
JSONArray jsonArray = new JSONArray(response);
for(int i = 0; i< jsonArray.length();i++){
if ((jsonArray.getJSONObject(i).optString("latitude") != "") && (jsonArray.getJSONObject(i).optString("longitude") != "")){
Places places = new Places();
places.setLatitude(jsonArray.getJSONObject(i).getDouble("latitude"));
places.setLongitude(jsonArray.getJSONObject(i).getDouble("longitude"));
places.setNome(jsonArray.getJSONObject(i).getString("nome"));
mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(places.getLatitude(),escolasMaps.getLongitude())).title(places.getNome()));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String err = (error.getMessage()==null)?"SD Card failed":error.getMessage();
Log.e("sdcard-err2:",err);
}
});
queue.add(stringRequest);
queue.start();
}
내가 해결하기 위해 수행 할 또 다른 문제는 마커의 제목의 항목에 값을 넣을 수 있습니다, 그래서 그것을 클릭하면 내가 대신 항목을 값을 전송하는 방법이다.
'http : // MyJsonURL'이 (가) 귀하의 요청에 응답하지 않을 것이라고 생각합니다. 내가 logcat이 SD에서 뭔가를 얻으려고한다고 말하는 이유를 이해하지 못합니다. 답변을 얻으려면 복사하여 붙여 넣은 코드에 대한 질문을 중지하십시오. – Chisko