0

地図上で船の位置をシミュレートしようとしているページがあります。これらの船の中には、ポリライン上の一定の割合の場所にあるものもあれば、単一のポイント マーカーにあるものもあります。

ポリラインに沿った一定の割合の船で、アイコンを正しく表示できます。私がやりたいのは、ポリライン全体ではなく、純粋にそのアイコンにイベントを添付することです。

私のコードは http://www.cleancruising.com.au/map_allShipLoc2.aspにあります

また、代わりに google.maps.geometry.spherical.computeDistanceBetween を使用して船の位置の LatLng を計算しようとしましたが、これは球形のジオメトリを使用しているため、平面マップではポイントが適切に変換されません。

4

1 に答える 1

1

船の場所のLatLngの計算については、Google MapsAPIv3グループのこのスレッドとその中の例を参照してください。

以下は、 Mike Williams(v2)epolyライブラリから変更されたGetPointAtDistance関数です。

// === A method which returns a GLatLng of a point a given distance along the path ===
// === Returns null if the path is shorter than the specified distance ===
google.maps.Polygon.prototype.GetPointAtDistance = function(metres) {
  // some awkward special cases
  if (metres == 0) return this.getPath().getAt(0);
  if (metres < 0) return null;
  if (this.getPath().getLength() < 2) return null;
  var dist=0;
  var olddist=0;
  for (var i=1; (i < this.getPath().getLength() && dist < metres); i++) {
    olddist = dist;
    dist += this.getPath().getAt(i).distanceFrom(this.getPath().getAt(i-1));
  }
  if (dist < metres) {return null;}
  var projection = this.getMap().getProjection(); 
  if (!projection) {
    alert("no projection");
    return; 
  }
  // Project 
  var p1= projection.fromLatLngToPoint(this.getPath().getAt(i-2));
  var p2= projection.fromLatLngToPoint(this.getPath().getAt(i-1));
  var m = (metres-olddist)/(dist-olddist);
  // alert("p1="+p1+" p2="+p2+" m="+m);
  // Unproject 
  return projection.fromPointToLatLng(new google.maps.Point( p1.x + (p2.x-p1.x)*m, p1.y + (p2.y-p1.y)*m));
}
于 2013-02-12T02:06:26.713 に答える