我想提请在Android的多geopoins之间的路径我想、路径、Android、geopoins

2023-09-04 05:59:56 作者:没了小猪的维尼

可能重复:   Is有在Android的谷歌地图导航的API?

最近我采取了Android开发作为一种业余爱好,并希望开发能够找到并使用谷歌地图跟踪用户位置的应用程序。

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

我已经看到了类似的应用程序,如Mytracks是开源的,但他们对我来说太复杂了现在。

他是我下面的code没有进口。

我想要做的就是创建geopoints数组。创建每次位置更改一个新的GeoPoint。然后,我尝试用一​​个for循环遍历每个GeoPoint对象,并绘制它们之间的路径。

在理想情况下我喜欢创造,看起来像这幅画的应用程序

 公共类跟踪扩展MapActivity实现LocationListener的{

   LocationManager locman;
   LocationListener的loclis;
   位置位置;
   私人MapView的地图;

   名单<的GeoPoint> geoPointsArray =新的ArrayList<的GeoPoint>();
   私人MapController控制器;
   字符串提供商= LocationManager.GPS_PROVIDER;
   双纬度;
   双LON;


   @覆盖
      公共无效的onCreate(包savedInstanceState){
         super.onCreate(savedInstanceState);
         的setContentView(R.layout.map);
         initMapView();
         initMyLocation();
         locman =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
         //locman.requestLocationUpdates(provider,60000,100,loclis);
         //位置= locman.getLastKnownLocation(供应商);

      }
   / **查找并初始化地图视图。 * /
      私人无效initMapView(){
         地图=(图形页面)findViewById(R.id.map);
         控制器= map.getController();
         map.setSatellite(假);
         map.setBuiltInZoomControls(真正的);
      }

      / **在地图上查找当前位置。 * /
      私人无效initMyLocation(){
         最后MyLocationOverlay覆盖=新MyLocationOverlay(本,地图);
         overlay.enableMyLocation();
         overlay.enableCompass(); //在仿真器不工作
         overlay.runOnFirstFix(新的Runnable(){
            公共无效的run(){
               //放大到当前位置
               controller.setZoom(24);
               controller.animateTo(overlay.getMyLocation());
            }
         });
         。map.getOverlays()加入(重叠);
      }

   @覆盖
   公共无效onLocationChanged(位置定位){
      如果(位置!= NULL){
         纬度= Location.getLatitude();
          LON = Location.getLongitude();
          的GeoPoint New_geopoint =新的GeoPoint((INT)(LAT * 1e6个),(INT)(LON * 1e6个));
          controller.animateTo(New_geopoint);

      }

   }
   类MyOverlay扩展覆盖{
       公共MyOverlay(){
       }
       公共无效画(油画画布,图形页面mapv,布尔影子){
       super.draw(帆布,mapv,阴影);

        投影投影= map.getProjection();
        路径P =新路径();
        的for(int i = 0; I< geoPointsArray.size();我++){
        如果(ⅰ== geoPointsArray.size() -  1){
            打破;
        }
        从=新的点对点();
        指向=新的点();
        projection.toPixels(geoPointsArray.get(i)中,从);
        projection.toPixels(geoPointsArray.get第(i + 1),到);
        p.moveTo(from.x,from.y);
        p.lineTo(to.x,to.y);
        }
        油漆mPaint =新的油漆();
        mPaint.setStyle(Style.STROKE);
        mPaint.setColor(0xFFFF0000地址);
        mPaint.setAntiAlias​​(真正的);
        canvas.drawPath(对,mPaint);
        super.draw(帆布,地图,阴影);
    }
}

   @覆盖
   公共无效onProviderDisabled(字符串提供商){
      // TODO自动生成方法存根

   }
   @覆盖
   公共无效onProviderEnabled(字符串提供商){
      // TODO自动生成方法存根

   }
   @覆盖
   公共无效onStatusChanged(字符串商,INT地位,捆绑演员){
      // TODO自动生成方法存根

   }
   @覆盖
   保护的布尔isRouteDisplayed(){
      // TODO自动生成方法存根
      返回false;
   }}
 

解决方案

阅读我的答案HERE.

你是在寻找什么是创建一个乌尔位置的变化,每次发射并记录了新的位置,可能是一个分贝的机器人服务。还可以创建一个应用程序,将使用数据从数据库绘制在地图视图的路径。

净利最高预增26倍 哪个行业这么火 连宁德时代也得抢货 更多新产能在路上

Possible Duplicate: Is there an API for Google Maps navigation in Android?

Recently I've taken up android development as a hobby and was looking to develop an application that can find and track a users position using Google Maps.

Once the application has a GPS lock, The application can track their movements by drawing a route using an overlay class.

I've seen similar applications like Mytracks that are open source but they're too complex for me right now.

He is my code below without the imports.

What I'm trying to do is create an array of geopoints. Every time the location changes a new geopoint is created. I then try to use a for loop to iterate through each geopoint and draw a path between them.

Ideally i'd love to create an application that looks like this picture

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;
   }}

解决方案

Read my answer HERE.

What you are looking at is to create an android service that is fired each time ur location changes and records the new location, probably to a db. Also create an app that will use data from the db to draw a path on a map-view.