0

Android アプリケーションがあり、Google マップにルートを入力しようとしています。このルートは、次のように JSON 配列に保存されます。

JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]

したがって、この場合、私は持っています

Point A=(-33.49088437162095, -70.64043194102163)

Point B=(-33.49423964397045, -70.63992768572683)

そして、私のルートまたはパスは A-----B

私はAndroidが初めてで、これを機能させる方法を考えていました。また、この場合、ルートは A-----B ですが、A----B----C----D の場合もあります。パス上に任意の数のポイントを持つことができます。

4

1 に答える 1

1

試すことができる 1 つのことは、Google マップの Polyline オブジェクトです: https://developers.google.com/maps/documentation/javascript/reference#Polyline ポイントの順序付けられたリスト (LatLng または配列のいずれか) を setPath() に指定します。 MVCArray または LatLng) をマップ上で接続すると、Google マップが仕様に合わせてポリラインを作成します。

// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);

あなたの場合、 JSONArray を setPath に渡すと問題なく動作するはずです。

工夫を凝らして道順を組み込みたい場合は、Google Directions API を使用する必要があります。 https://developers.google.com/maps/documentation/javascript/directions

// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
    origin: start,
    destination: end,
    waypoints: waypts,
    optimizeWaypoints: [type Boolean],
    travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        // if successful, this will run
    }
});

オブジェクトの構築が完了したら、次のように setMap(map:Map) を実行して表示できるはずです。

routeLine.setMap(map)
于 2012-10-24T02:57:56.020 に答える