Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GPS追踪(用户在谷歌地图上移动时画线)_Java_Android_Google Maps_Gps - Fatal编程技术网

Java GPS追踪(用户在谷歌地图上移动时画线)

Java GPS追踪(用户在谷歌地图上移动时画线),java,android,google-maps,gps,Java,Android,Google Maps,Gps,我试图显示谷歌地图,并在用户行走Gps追踪应用程序时画一条线 我有两个问题: 1-地图不显示,只显示地图的网格 2-当用户行走时,我将地质点保存在一个列表中,我可以看到指示我在地图上位置的点移动!但两者之间没有任何联系。 你能查一下我下面的代码和建议吗 额外问题:我是否必须在一个单独的java文件上写自己的代码,因为现在我有一个文件上有这个代码?要让我的应用程序运行良好,是否有必要选择GoogleAPI而不是标准api package com.example.geoart; public cl

我试图显示谷歌地图,并在用户行走Gps追踪应用程序时画一条线 我有两个问题: 1-地图不显示,只显示地图的网格 2-当用户行走时,我将地质点保存在一个列表中,我可以看到指示我在地图上位置的点移动!但两者之间没有任何联系。 你能查一下我下面的代码和建议吗

额外问题:我是否必须在一个单独的java文件上写自己的代码,因为现在我有一个文件上有这个代码?要让我的应用程序运行良好,是否有必要选择GoogleAPI而不是标准api

package com.example.geoart;

public class HelloGoogleMaps2 extends MapActivity implements LocationListener {


 LocationManager locman;
  LocationListener loclis;
  Location Location;
  public  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.main);
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.mapview);
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));
    geoPointsArray.add(New_geopoint); //add geopoints to my array//
    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.setDither(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);

   /*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;
    }
           }
我的main.Xml代码

     <?xml version="1.0" encoding="utf-8"?>
       <com.google.android.maps.MapView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/mapview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:clickable="true"
 android:apiKey="AIzaSyD2epTuEtf-L_UFtQ_7vtQKQdJJ3hMA5YM"


/>

请转到Google Map V2,因为Google Map V1已弃用。转到:使用多段线在图形上绘制线map@Simple计划谢谢你的回答。我使用的是谷歌地图V2。我在这里遵循了这个教程,非常清晰和简单,以防有人需要这些步骤。还有其他建议吗?非常感谢!