Android 安卓:我的地图没有';“不要去”;“我的位置”;

Android 安卓:我的地图没有';“不要去”;“我的位置”;,android,maps,location,Android,Maps,Location,我已经创建了一张地图,但在手机上,它不会移动到我的位置(从gps获取)。为什么? 因为我需要检索用户位置,如果我找到了,请将贴图设置为该点的动画并刷新它(从数据库中获取pin)。在否定的情况下,我把中心放在米兰 public class Mappa extends MapActivity { private MapView mapView; double latitudine=0; double longitudine=0; int kilometri=20; @Override protect

我已经创建了一张地图,但在手机上,它不会移动到我的位置(从gps获取)。为什么? 因为我需要检索用户位置,如果我找到了,请将贴图设置为该点的动画并刷新它(从数据库中获取pin)。在否定的情况下,我把中心放在米兰

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){

    }
}
}
公共类Mappa扩展了MapActivity{
私有地图视图;
双纬度=0;
双纵联=0;
int-ri=20;
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mappa);
mapView=(mapView)findViewById(R.id.mapView);
MapController MapController=mapView.getController();
最终MyLocation Overlay MyLocation Overlay;
mapView.SetBuilTinZoomControl(真);
List mapOverlays=mapView.getOverlays();
Drawable Drawable=this.getResources().getDrawable(R.Drawable.pin_bioscalin);
MyOverlays itemizedoverlay=新的MyOverlays(可绘制,此);
//米兰
纬度=45.464164;
longitudine=9.190321;
地质点mio_点=新的地质点((int)(纬度*1E6),(int)(经度*1E6));
地图控制器设置中心(百万分之一点);
mapController.animateTo(米欧点);
mapController.setZoom(11);
//全球定位系统
LocationManager mlocManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
LocationListener mlocListener=新建MyLocationListener();
mlocManager.RequestLocationUpdate(LocationManager.GPS_提供程序,0,0,mlocListener);
//法玛西
Database_mio db=新数据库(this);
openDataBase();
光标数据=db.elenco_negozi_mappa(纬度、经度、千米);
data.moveToFirst();
做{
String id\u farmacia=data.getString(数据
.getColumnIndex(“_id”);
字符串ragione_farmacia=data.getString(数据
.getColumnIndex(“ragione”);
String indirizzo_farmacia=data.getString(数据
.getColumnIndex(“ragione”);
int latitude_farmacia=(int)(data.getDouble(data
.getColumnIndex(“lat”)*1E6);
int经度_farmacia=(int)(data.getDouble(data
.getColumnIndex(“lng”)*1E6);
地质点=新的地质点(纬度、经度);
OverlayItem OverlayItem=新的OverlayItem(point、ragione_farmacia、indirizzo_farmacia);
itemizedoverlay.addOverlay(overlayitem);
}while(data.moveToNext());
添加(itemizedoverlay);
//圆盘机
ImageView img=(ImageView)findViewById(R.id.image\u mia\u map);
setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
Intent disclamer=newintent(getParent(),disclamer.class);
disclamer.putExtra(“da_dove”、“Mappa”);
TabGroupActivity parentActivity=(TabGroupActivity)getParent();
家长活动。启动儿童活动(“Disclamer”,Disclamer);
}
});
}
/*类我的位置侦听器*/
公共类MyLocationListener实现LocationListener{
@凌驾
位置更改后的公共无效(位置loc){
loc.getLatitude();
loc.getLongitude();
String Text=“La mia posizione:”+“Latitudine=“+loc.getLatitude()+”Longitudine=“+loc.getLongitude()”;
地质点mio_点=新的地质点((int)(位置getLatitude()*1E6),(int)(位置getLatitude()*1E6));
mapView.getController().setCenter(百万分之一点);
mapView.getController().animateTo(mio_点);
Toast.makeText(getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
Toast.makeText(getApplicationContext(),“Gps禁用”,Toast.LENGTH_SHORT).show();
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
Toast.makeText(getApplicationContext(),“Gps能力”,Toast.LENGTH\u SHORT.show();
}
@凌驾
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
}
}
}

感谢大家。

您是否在清单中提供了有关GPSok的权限?它可以工作,但显示位置需要很多时间!!!gps太慢了!p、 失效功能让地图重新加载?因此,pin的查询重新完成了?gps提供商需要时间获取位置,而且它在户外工作效率很高。好的,它可以工作。但是对于重新加载和重新执行查询?