2011-03-09 42 views
3

可能重复:
Is there an API for Google Maps navigation in Android?我想提请多个geopoins之间的路径中的Android

最近,我已经采取了Android开发作为一种业余爱好,并希望开发一个应用程序,可以使用Google地图查找并跟踪用户的位置。

一旦应用程序有一个GPS锁定,应用程序可以通过使用覆盖类绘制路径跟踪他们的行踪。

我见过像Mytracks是开源的类似的应用程序,但他们目前正对我来说太复杂。

他是我的代码下面没有进口。

我想要做的就是创建geopoints的数组。每当位置发生变化时都会创建一个新的地址。然后,我尝试使用for循环遍历每个地址点并在它们之间绘制路径。

理想我很乐意来创建看起来像这幅画

enter image description here

public class Tracking extends MapActivity implements LocationListener { 

    LocationManager locman; 
    LocationListener loclis; 
    Location Location; 
    private MapView map; 

    List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>(); 
    private MapController controller; 
    String provider = LocationManager.GPS_PROVIDER; 
    double lat; 
    double lon; 


    @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 
     initMapView(); 
     initMyLocation(); 
     locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
     //locman.requestLocationUpdates(provider,60000, 100,loclis); 
     //Location = locman.getLastKnownLocation(provider); 

     } 
    /** Find and initialize the map view. */ 
     private void initMapView() { 
     map = (MapView) findViewById(R.id.map); 
     controller = map.getController(); 
     map.setSatellite(false); 
     map.setBuiltInZoomControls(true); 
     } 

     /** Find Current Position on Map. */ 
     private void initMyLocation() { 
     final MyLocationOverlay overlay = new MyLocationOverlay(this, map); 
     overlay.enableMyLocation(); 
     overlay.enableCompass(); // does not work in emulator 
     overlay.runOnFirstFix(new Runnable() { 
      public void run() { 
       // Zoom in to current location 
       controller.setZoom(24); 
       controller.animateTo(overlay.getMyLocation()); 
      } 
     }); 
     map.getOverlays().add(overlay); 
     } 

    @Override 
    public void onLocationChanged(Location location) { 
     if (Location != null){ 
     lat = Location.getLatitude(); 
      lon = Location.getLongitude(); 
      GeoPoint New_geopoint = new GeoPoint((int)(lat*1e6),(int)(lon*1e6)); 
      controller.animateTo(New_geopoint); 

     } 

    } 
    class MyOverlay extends Overlay{ 
     public MyOverlay(){ 
     } 
     public void draw(Canvas canvas, MapView mapv, boolean shadow){ 
     super.draw(canvas, mapv, shadow); 

     Projection projection = map.getProjection(); 
     Path p = new Path(); 
     for (int i = 0; i < geoPointsArray.size(); i++) { 
     if (i == geoPointsArray.size() - 1) { 
      break; 
     } 
     Point from = new Point(); 
     Point to = new Point(); 
     projection.toPixels(geoPointsArray.get(i), from); 
     projection.toPixels(geoPointsArray.get(i + 1), to); 
     p.moveTo(from.x, from.y); 
     p.lineTo(to.x, to.y); 
     } 
     Paint mPaint = new Paint(); 
     mPaint.setStyle(Style.STROKE); 
     mPaint.setColor(0xFFFF0000); 
     mPaint.setAntiAlias(true); 
     canvas.drawPath(p, mPaint); 
     super.draw(canvas, map, shadow); 
    } 
} 

    @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 

    } 
    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    }} 
+0

这里有什么问题? – 2011-03-09 08:52:08

+0

我想跟踪我的Android设备,当它的位置发生变化,我想看到它的路径。 – 2011-03-09 08:53:57

+0

你需要问一个具体问题:http://stackoverflow.com/faq – 2011-03-09 09:51:11

回答

0

的应用程序读取我的回答HERE

你在看什么是创建一个android服务,每当你的位置发生变化,并记录新的位置,可能是一个数据库。还要创建一个应用程序,该应用程序将使用数据库中的数据在地图视图上绘制路径。