Привет, я пишу приложение, которое получает текущую силу и долготу и преобразует ее в соответствующий адрес. Я использую google maps api v2.Using google api iam, способный сделать это. Но когда-нибудь мне нужно перезапустить мое устройство, чтобы избежатьget adrees using json
Сервис не доступен выпуск
. когда гугле я нашел, что использование JSON как option.i новичок в JSON, я попробовал некоторый код, но не получаю адрес
Это мой код с помощью Google API
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.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.maps.GeoPoint;
public class MapActivity extends FragmentActivity {
private GoogleMap map;
//Location location;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new GpsMapLocationActivity(getBaseContext());
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setMyLocationEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, menu);
return true;
}
private class GpsMapLocationActivity implements LocationListener{
Marker marker;
Context mcontext;
public GpsMapLocationActivity(Context context){
super();
mcontext=context;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) {
double latitude=location.getLatitude();
double longitude=location.getLongitude();
LatLng loca=new LatLng(latitude,longitude);
Toast.makeText(getApplicationContext(),"" +loca,
Toast.LENGTH_LONG).show();
Geocoder geoCoder=new Geocoder(mcontext);
String address="";
try {
List<Address> addresses = geoCoder.getFromLocation(latitude,longitude,1);
if (addresses.size() > 0) {
for (int index = 0;
index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}catch (IOException e) {
e.printStackTrace();
}
Log.i("Addresss", ""+address);
Toast.makeText(getApplicationContext(),"" +address,
Toast.LENGTH_LONG).show();
CameraPosition cmp= new CameraPosition.Builder().target(loca).zoom(14).bearing(90).tilt(30).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cmp));
if(marker!=null){
marker.remove();
}
marker = map.addMarker(new MarkerOptions()
.position(loca)
.title("MyMap")
.snippet("My Map View")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_gps)));
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
}
}
пожалуйста, помогите мне
заранее спасибо ..
Может быть, вы [пределы] (https://developers.google.com/maps/documentation/geocoding/#Limits) вопрос? –
Итак, где ваш код с помощью json? Я вижу только «Геокодер». –
Возможный дубликат [Получить текущее местоположение с помощью json] (http://stackoverflow.com/questions/20238197/get-current-location-using-json) – Megamind