Когда я изменяю местоположение gps телефона, программа просто вылетает, кажется, что я не могу найти идентификатор карты Google (найти по идентификатору) Это мой код:
package Maps.GeoLocation.Google;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MapsGeoLocationActivity extends MapActivity {
MapController mControl;
GeoPoint GeoP;
MapView mapV;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
public void maps(double pLati, double pLongi)
{
mapV = (MapView) findViewById(R.id.mapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
GeoP = new GeoPoint ((int) (pLati *1E6), (int) (pLongi *1E6));
mControl = mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(13);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
class mylocationlistener implements LocationListener {
double pLong;
double pLat;
@Override
public void onLocationChanged(Location location) {
MapsGeoLocationActivity ff = new MapsGeoLocationActivity();
pLong = location.getLongitude();
pLat = location.getLatitude();
//textLat.setText(Double.toString(pLat));
//textLong.setText(Double.toString(pLong));
ff.maps(pLat, pLong);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Main.xml(Это не может быть неправильно, но если вы, ребята, спросите)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="apikey"
/>
</LinearLayout>
LogCat: http://img195.imageshack.us/img195/5655/16325616.png