-2

我想在 google maps api 给出的方向的折线上每 5 或 10 公里添加一个标记。像这样的东西:

http://www.geocodezip.com/v3_polyline_example_kmmarkers_0.html

但与谷歌方向的

4

2 回答 2

1

我找到了一个像魅力一样起作用的公式。它在给定点之间每 8 米添加一个标记。

我从这里得到了公式:如何计算两个给定点和给定距离之间的点?

F点A点,B点;

    var diff_X = pointB.X - pointA.X;
    var diff_Y = pointB.Y - pointA.Y;
    int pointNum = 8;

    var interval_X = diff_X / (pointNum + 1);
    var interval_Y = diff_Y / (pointNum + 1);

    List<PointF> pointList = new List<PointF>();
    for (int i = 1; i <= pointNum; i++)
    {
        pointList.Add(new PointF(pointA.X + interval_X * i, pointA.Y + interval_Y*i));
    }

Android 我的最终结果翻译

    //GeoPoint PointF, pointA, pointB;

    Double diff_X = lat2 - lat1;
    Double diff_Y = lon2 - lon1;
    int pointNum = 8;

    Double interval_X = diff_X / (pointNum + 1);
    Double interval_Y = diff_Y / (pointNum + 1);

    //ArrayList<GeoPoint> geoPoints = new ArrayList<>();
    List<GeoPoint> pointList = new ArrayList<>();
    for (int i = 1; i <= pointNum; i++)
    {
        GeoPoint g = new GeoPoint(lat1 + interval_X * i, lon1 + interval_Y*i);
        pointList.add(g);
        itemizedLayer.addItem(createMarkerItem(g, R.drawable.ic_my_location));
    }


    map.map().updateMap(true);
于 2018-03-05T17:45:28.547 回答
0

给定起点、初始方位和距离,这将计算沿(最短距离)大圆弧行进的目的地点和最终方位。

var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
              Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                     Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));

地球的半径 ( R) 为 6371000 米。 brng是以度为单位的行进方向(0 = 北)。

然后使用此功能将标记添加到地图

function setMarkers(map, locations) {
  // Add markers to the map

  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.
  var image = {
    url: 'images/beachflag.png',
    // This marker is 20 pixels wide by 32 pixels tall.
    size: new google.maps.Size(20, 32),
    // The origin for this image is 0,0.
    origin: new google.maps.Point(0,0),
    // The anchor for this image is the base of the flagpole at 0,32.
    anchor: new google.maps.Point(0, 32)
  };
  var shadow = {
    url: 'images/beachflag_shadow.png',
    // The shadow image is larger in the horizontal dimension
    // while the position and offset are the same as for the main image.
    size: new google.maps.Size(37, 32),
    origin: new google.maps.Point(0,0),
    anchor: new google.maps.Point(0, 32)
  };
  // Shapes define the clickable region of the icon.
  // The type defines an HTML <area> element 'poly' which
  // traces out a polygon as a series of X,Y points. The final
  // coordinate closes the poly by connecting to the first
  // coordinate.
  var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
  };
  for (var i = 0; i < locations.length; i++) {
    var beach = locations[i];
    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
    });
  }
}

编辑该函数以获得正确的标记图标,并为您要放置的每个标记调用它。

于 2013-08-08T03:16:41.537 回答