0

マップを作成しましたが、携帯電話では自分の場所 (GPS から取得) に移動しません。なぜ?ユーザーの場所を取得する必要があるため、見つかった場合は、そのポイントまでマップをアニメーション化し、更新します (データベースからピンを取得するため)。否定的な場合は、中心をミラノに置きます。

public class Mappa extends MapActivity {
private MapView mapView;
double latitudine=0;
double longitudine=0;
int kilometri=20;
@Override
protected boolean isRouteDisplayed() {
    return false;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mappa);
    mapView = (MapView) findViewById(R.id.mapview);
    MapController mapController = mapView.getController();
    final MyLocationOverlay myLocationOverlay;
    mapView.setBuiltInZoomControls(true);
    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.pin_bioscalin);
    MyOverlays itemizedoverlay = new MyOverlays(drawable, this);
    // milano
    latitudine = 45.464164;
    longitudine = 9.190321;
    GeoPoint mio_point = new GeoPoint((int)(latitudine*1E6), (int)(longitudine*1E6));
    mapController.setCenter(mio_point);
    mapController.animateTo(mio_point);
    mapController.setZoom(11);
    // GPS
    LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener mlocListener = new MyLocationListener();
    mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    // farmacie
    Database_mio db=new Database_mio(this); 
    db.openDataBase(); 
    Cursor data=db.elenco_negozi_mappa(latitudine,longitudine,kilometri);
    data.moveToFirst();
    do {
        String id_farmacia = data.getString(data
                .getColumnIndex("_id"));
        String ragione_farmacia = data.getString(data
                .getColumnIndex("ragione"));
        String indirizzo_farmacia = data.getString(data
                .getColumnIndex("ragione"));
        int latitude_farmacia = (int) (data.getDouble(data
                .getColumnIndex("lat")) * 1E6);
        int longitude_farmacia = (int) (data.getDouble(data
                .getColumnIndex("lng")) * 1E6);
        GeoPoint point = new GeoPoint(latitude_farmacia,longitude_farmacia);
        OverlayItem overlayitem = new OverlayItem(point,ragione_farmacia,indirizzo_farmacia);
        itemizedoverlay.addOverlay(overlayitem);
    } while (data.moveToNext());
    mapOverlays.add(itemizedoverlay);
    // disclamer
    ImageView img = (ImageView) findViewById(R.id.image_mia_map);
    img.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent disclamer = new Intent(getParent(), Disclamer.class);
            disclamer.putExtra("da_dove", "Mappa");
            TabGroupActivity parentActivity = (TabGroupActivity)getParent();
            parentActivity.startChildActivity("Disclamer", disclamer);
        }
    });
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener{
    @Override
    public void onLocationChanged(Location loc){
        loc.getLatitude();
        loc.getLongitude();
        String Text = "La mia posizione: "+"Latitudine = "+loc.getLatitude()+"Longitudine = "+loc.getLongitude();
        GeoPoint mio_point = new GeoPoint((int)(loc.getLatitude()*1E6), (int)(loc.getLongitude()*1E6));
        mapView.getController().setCenter(mio_point);
        mapView.getController().animateTo(mio_point);
        Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onProviderDisabled(String provider){
        Toast.makeText( getApplicationContext(),"Gps disabilitato",Toast.LENGTH_SHORT ).show();
    }
    @Override
    public void onProviderEnabled(String provider){
        Toast.makeText( getApplicationContext(),"Gps abilitato",Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras){

    }
}
}

ありがとうございます。

4

0 に答える 0