1

Jquery getJson()を使用して、Google Maps3APIに表示されるjsonを生成しています。:polylineのようにポリラインを表示したい -簡単な例

 function initialize() {
    var myLatLng = new google.maps.LatLng(0, -180);
    var myOptions = {
      zoom: 3,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var flightPlanCoordinates = [
        new google.maps.LatLng(37.772323, -122.214897),
        new google.maps.LatLng(21.291982, -157.821856),
        new google.maps.LatLng(-18.142599, 178.431),
        new google.maps.LatLng(-27.46758, 153.027892)
    ];
    var flightPath = new google.maps.Polyline({
      path: flightPlanCoordinates,
      strokeColor: "#FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

   flightPath.setMap(map);
  }

JQuery:

$.getJSON("routefinder", { "lat1": lat1 , "lng1": lng1 , "lat2": lat2 , "lng2": lng2 }, function(json) {
    var poly = new google.maps.Polyline({
      path: json,
      strokeColor: "#FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

   poly.setMap(map);
});

$ .getJSONは、[new google.maps.LatLng(lat、lng)]形式のポリライン座標を持つ文字列を返します。

 [ new google.maps.LatLng(53.369567, -6.323699),  new google.maps.LatLng(53.367705, -6.317386),new google.maps.LatLng(53.337705,-6.917386), new google.maps.LatLng(53.397705,-6.47386)]

しかし、行は生成されません。google.maps.LatLngオブジェクトを含むjson配列を返すことはできますか?または、ポリラインを表示するための最良の方法は何でしょうか。

4

1 に答える 1

2

私のサイト(http://www.cyclistsroadmap.com)には、ルートファインダー用の似たようなものがあります。

Googleのルートファインダーを使用している場合は、戻ってきたDirectionsObjectを使用できます。データベースに保存したデータを使用するときは、すべてのlat、lng座標を含む2D配列として送り返します。(ただし、$。getJSON呼び出しではなく、通常のAJAX呼び出しを実行します。AJAXはJSON文字列を返します。

于 2010-06-21T03:03:42.490 に答える