1. <legend id='Z4BFn'><style id='Z4BFn'><dir id='Z4BFn'><q id='Z4BFn'></q></dir></style></legend><tfoot id='Z4BFn'></tfoot>

        <small id='Z4BFn'></small><noframes id='Z4BFn'>

        <i id='Z4BFn'><tr id='Z4BFn'><dt id='Z4BFn'><q id='Z4BFn'><span id='Z4BFn'><b id='Z4BFn'><form id='Z4BFn'><ins id='Z4BFn'></ins><ul id='Z4BFn'></ul><sub id='Z4BFn'></sub></form><legend id='Z4BFn'></legend><bdo id='Z4BFn'><pre id='Z4BFn'><center id='Z4BFn'></center></pre></bdo></b><th id='Z4BFn'></th></span></q></dt></tr></i><div id='Z4BFn'><tfoot id='Z4BFn'></tfoot><dl id='Z4BFn'><fieldset id='Z4BFn'></fieldset></dl></div>

          <bdo id='Z4BFn'></bdo><ul id='Z4BFn'></ul>
      2. 在 Android 中步行/驾驶时更新位置标记并在 Googl

        时间:2023-09-01
                <legend id='0A1ye'><style id='0A1ye'><dir id='0A1ye'><q id='0A1ye'></q></dir></style></legend>

                  <bdo id='0A1ye'></bdo><ul id='0A1ye'></ul>
                • <i id='0A1ye'><tr id='0A1ye'><dt id='0A1ye'><q id='0A1ye'><span id='0A1ye'><b id='0A1ye'><form id='0A1ye'><ins id='0A1ye'></ins><ul id='0A1ye'></ul><sub id='0A1ye'></sub></form><legend id='0A1ye'></legend><bdo id='0A1ye'><pre id='0A1ye'><center id='0A1ye'></center></pre></bdo></b><th id='0A1ye'></th></span></q></dt></tr></i><div id='0A1ye'><tfoot id='0A1ye'></tfoot><dl id='0A1ye'><fieldset id='0A1ye'></fieldset></dl></div>
                • <small id='0A1ye'></small><noframes id='0A1ye'>

                    <tbody id='0A1ye'></tbody>
                  <tfoot id='0A1ye'></tfoot>

                  本文介绍了在 Android 中步行/驾驶时更新位置标记并在 Google 地图上绘制路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想创建一个类似于 Google 地图的功能.每当有人开始步行/开车时,我都想更新我的位置标记.我正在考虑使用 LocationListner 的 onLocationChange 方法,但我不确定.我也喜欢在谷歌地图上绘制更新位置的路径.

                  I want to create a functionality like Google Maps. I want to update my location marker whenever a person start walking/driving. I am thinking of using onLocationChange method of LocationListner but I am not sure. I also like to draw the path with updating location on the Google Maps.

                  欢迎所有建议.

                  ItemizedOverlay:-

                  ItemizedOverlay:-

                  public class LocationOverlay extends ItemizedOverlay<OverlayItem>{
                  
                      private List<OverlayItem> myOverlays;
                      Path path;
                      static int cnt = -1;
                      public LocationOverlay(Drawable defaultMarker) {
                          super(boundCenterBottom(defaultMarker));
                          System.out.println("Normal...");
                          myOverlays = new ArrayList<OverlayItem>();
                      }
                  
                  
                      public void addOverlay(OverlayItem overlay) {
                          System.out.println("Add Overlay called");
                          myOverlays.add(overlay);
                          populate();
                              cnt++;
                      }
                  
                      @Override
                      protected OverlayItem createItem(int i) {
                          return myOverlays.get(i);
                      }
                  
                      public void removeItem(int i) {
                          myOverlays.remove(i);
                          populate();
                      }
                  
                      @Override
                      public int size() {
                          return myOverlays.size();
                      }
                  
                      @Override
                      public void draw(Canvas canvas, final MapView mapView, boolean shadow) {
                  
                  
                             if (shadow) {
                              paint.setDither(true);
                              paint.setColor(Color.RED);
                              paint.setStyle(Paint.Style.STROKE);
                              paint.setStrokeJoin(Paint.Join.ROUND);
                              paint.setStrokeCap(Paint.Cap.ROUND);
                              paint.setStrokeWidth(4);
                  
                              path = new Path();
                              Point point1 = new Point();
                              Projection projection = mapView.getProjection();
                              if (myOverlays.size() > 1) {
                  
                                  System.out.println(">>>>>>>>>>>");
                  
                                  for (int i = 0, j=i; i < myOverlays.size(); i++) {
                                  Point point1 = new Point();
                                  Point point2 = new Point();
                                  projection.toPixels(myOverlays.get(i).getPoint(), point1);
                  
                                  System.out.println(">>>>>>>>>>>");
                  
                                  projection.toPixels(myOverlays.get(j++).getPoint(), point2);
                                  System.out.println("Point == " + j);
                  
                                  path.moveTo(point2.x, point2.y);
                                  path.lineTo(point1.x, point1.y);
                                  canvas.drawPath(path, paint);
                                  super.draw(canvas, mapView, shadow);
                              }   
                              }
                          }
                          canvas.drawPath(path, paint);
                          super.draw(canvas, mapView, shadow);
                      }
                  }
                  

                  注意 - 对于单个 locationChanged,draw 方法会被多次调用.

                  -

                  每当发生任何位置更改事件触发时,我都可以绘制路线,但我在那里遇到了一个小问题.它也每次都从根目录绘制路径.我希望它从最后一个位置开始绘制路径(即从最后一个位置连接到下一个位置).我附上一张图片以便更好地理解.

                  I am able to draw the route whenever there is any location changed event fire but I am facing a small problem there. Its also drawing path from root every time. I want that from last place it should start drawing the path (i.e connecting from last to next location). I am attaching one image for better understanding.

                  从图中可以看出,起点也与终点相连.我不想要这个.对此有任何想法.

                  From the image you can see that the starting point is also connected to last point. I don't want this. Any idea on this.

                  推荐答案

                  使用 MyLocationOverlay.您需要做的就是将此叠加层添加到您的 MapView.比如:

                  Current location can be easily drawn with MyLocationOverlay. What you need to do - is to add this overlay to your MapView. Something like:

                  mapView.addOverlay(new MyLocationOverlay(context, mapView));
                  

                  默认位置点会自动绘制,一移动就会更新

                  The default location dot will be drawn automatically and will be updated as soon as you move

                  路线有点棘手,但仍然没有火箭科学.您需要做的是扩展 Overlay 类并实现 draw() 逻辑.您需要跟踪您旅行的 GeoPoints 并将它们投影到地图上(在您的叠加层的 draw() 中,您可以向 mapView 询问 Projection 实例 - getProjection().您可以使用此投影将 GeoPoints 映射到您的地图坐标).一旦您拥有 GeoPoints 列表 - 您可以创建一个 Path 和在画布上绘制此路径

                  With route it is a bit trickier, but still there is no rocket science in there. What you need to do - is to extend Overlay class and implement draw() logic. You need to keep track of GeoPoints you travelled and project them on a map (in your overlay's draw() you can ask your mapView for a Projection instance - getProjection(). You can use this projection to map GeoPoints to your map coordinates). As soon as you have list of GeoPoints - you can create a Path and draw this Path on a Canvas

                  如何在地图上绘制路径的简化示例(我的项目中使用了一些自定义类,但你应该明白):

                  The simplified example how to draw path on a map (there are some custom classes I use in my project, but you should get an idea):

                  Path path;
                  
                  @Override
                  public void draw(Canvas canvas, final MapView mapView, boolean shadow)
                  {
                      Projection proj = mapView.getProjection();
                      updatePath(mapView,proj);
                      canvas.drawPath(path, mPaint);
                  }
                  
                  protected void updatePath(final MapView mapView, Projection proj)
                  {
                      path = new Path();
                  
                      proj.toPixels(mPoints.get(0).point, p);
                      path.moveTo(p.x, p.y);
                  
                      for(RouteEntity.RoutePoint rp : mPoints)
                      {
                          proj.toPixels(rp.point, mPoint);
                          path.lineTo(mPoint.x, mPoint.y);
                      }
                  }
                  

                  这篇关于在 Android 中步行/驾驶时更新位置标记并在 Google 地图上绘制路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何防止 Phonegap 应用程序中的地理定位双重提示 下一篇:navigator.geolocation.getCurrentPosition 在 android google c

                  相关文章

                  最新文章

                  <i id='oX6Fh'><tr id='oX6Fh'><dt id='oX6Fh'><q id='oX6Fh'><span id='oX6Fh'><b id='oX6Fh'><form id='oX6Fh'><ins id='oX6Fh'></ins><ul id='oX6Fh'></ul><sub id='oX6Fh'></sub></form><legend id='oX6Fh'></legend><bdo id='oX6Fh'><pre id='oX6Fh'><center id='oX6Fh'></center></pre></bdo></b><th id='oX6Fh'></th></span></q></dt></tr></i><div id='oX6Fh'><tfoot id='oX6Fh'></tfoot><dl id='oX6Fh'><fieldset id='oX6Fh'></fieldset></dl></div>

                  1. <tfoot id='oX6Fh'></tfoot><legend id='oX6Fh'><style id='oX6Fh'><dir id='oX6Fh'><q id='oX6Fh'></q></dir></style></legend>

                    1. <small id='oX6Fh'></small><noframes id='oX6Fh'>

                        <bdo id='oX6Fh'></bdo><ul id='oX6Fh'></ul>