2011-11-13 39 views
0

我正在使用Google Maps API制作Android应用程序。我加载地图来找到我的位置,但我遇到了问题。当我移动到另一个位置时,我立即返回了以屏幕为中心的位置。我宁愿地图会保持在我已经移动的地步。如何移动谷歌地图?

这里是我的代码:

private void setCurrentLocation(Location location) 
{    
    if(location != null) 
    { 
     // Aggiorna la location 
     Lat = location.getLatitude(); 
     Long = location.getLongitude(); 

     int latitudeE6 = (int) Math.floor(Lat * 1.0E6); 
     int longitudeE6 = (int) Math.floor(Long * 1.0E6); 

     GeoPoint p1 = new GeoPoint(latitudeE6, longitudeE6); 
     GeoPoint p2 = new GeoPoint(currentLatitude, currentLongitude); 

     // Aggiorna la posizione corrente 
     currentLatitude = latitudeE6; 
     currentLongitude = longitudeE6; 

     // Sposta la posizione corrente sulla mappa di F_Map 
     F_Map.mapController.setCenter(p1); 

     // Calcola i metri appena fatti 
     float dist = Distance.getDistance(p1, p2) *1000; 

     if(dist > 1) // maggiore di 1 metro 
     {        
      Toast.makeText(getApplicationContext(), "distance: "+dist,Toast.LENGTH_SHORT).show(); 

      try 
      { 
       SendMyPositionToDB(currentLatitude, currentLongitude); 
      } catch(IOException e) { 
       e.printStackTrace(); 
      }        
     } 
    } 
} 

回答

0

您可以设置:

F_Map.mapController.setCenter(p2); 

相反P1的?

+0

问题不在于坐标。 现在每当GPS检测到一个班次(map.setCenter(); onChangeLocation())时,地图就会移动。 我想确保当您触摸屏幕时,setCenter被禁用,然后在您按下特殊按钮时重新激活。 – user1023571