こんにちは。
現在大学の研究の一環で、Google Maps APIについて学習しております。
APIに関して全くの初心者ですが、質問があります。
今回必要としている機能として、羊ケ丘展望台から札幌駅へ向かう2ルートを地図上に表示させたいのですが
下記に示すようなものが現在できております。
ですが、まだ一つのルートしか表示できません。
このルートをそのままに、同じ出発地と到着地で(43.034047,141.359536)を経由するルートを赤いラインで追加したいと思っているのですが、
この場合はどういったコードになるのでしょうか?
かなりいろいろ調べてみましたが、初心者ゆえなかなか上手くできません。
どなたか知識をお持ちの方がいらっしゃいましたら、ご助力頂きたく存じます。
何卒宜しくお願い致します。
<html>
<head>
<title>Google Maps V3</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<style type="text/css">
v\:* {behavior:url(#default#VML);}
html, body {width: 100%; height: 100%}
body {top:0px;left:0px;margin-top: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 0px}
</style>
<script src="http://maps.google.com/maps/api/js?sensor=false" …
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4. …
<script>
google.maps.event.addDomListener(window, 'load', function()
{
var mapObj;
var lng = 139.8131925612688;
var lat = 35.73369469149347;
var mapOptions = {
zoom: 11,
center: null,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true
};
mapObj = new google.maps.Map(document.getElementById('gmap'), mapOptions);
// ルートを表示するマップを設定
var directionsRenderer = new google.maps.DirectionsRenderer();
directionsRenderer.setMap(mapObj);
// 開始地点と終了地点、ルーティングの種類の設定
var request = {
origin: "羊ケ丘展望台",
destination: "札幌駅",
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
// ルート検索を行う
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(result, status)
{
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
}
});
// Monitor the window resize event and let the map know when it occurs
if (window.attachEvent) {
window.attachEvent("onresize", function() {this.map.onResize()} );
} else {
window.addEventListener("resize", function() {this.map.onResize()} , false);
}
});
</script>
</head>
<body>
<div id="gmap" style="top:0px;left:0px;width: 100%; height: 100%;">
</div>
</body>
</html>
A 回答 (1件)
- 最新から表示
- 回答順に表示
No.1
- 回答日時:
たとえば現状のルート表示処理のあとに、
// 別ルート表示処理
var directionsRenderer2 = new google.maps.DirectionsRenderer({polylineOptions:{strokeColor: "red"}});
directionsRenderer2.setMap(mapObj);
request = {
origin: "羊ケ丘展望台",
destination: "札幌駅",
travelMode: google.maps.DirectionsTravelMode.DRIVING,
waypoints: [
{
location: new google.maps.LatLng(43.034047,141.359536)
}
]
};
directionsService.route(request, function(result, status)
{
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer2.setDirections(result);
}
});
こんなのを追加すればいいのではないでしょうか。(処理をまとめたりするのはご自身で・・)
ただ、自分は今回の質問を拝見して初めてGoogle Maps APIを触った、というレベルですので、もっとうまい方法もあるのだと思います。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
SCRIPT5007: 未定義または NULL...
-
フォーカス移動抑止について
-
JavaScriptでiframeの内容を「...
-
リンク移動先のURLを取得
-
初心者javascript ウィンドウサ...
-
ナンバーズ 4 の数列をランダム...
-
JavaScriptでのEnterキーとAlt+...
-
数日前等の日付を表示したいの...
-
ホームページに日付によりかわ...
-
インラインフレーム内から親フ...
-
【jquery】EasyUIのSubGridにMy...
-
function の return 値を表示し...
-
インラインフレームの、リンク...
-
JavaScript でキーを送る
-
iframeの中から親ページをスム...
-
<a href="#" …>の意味を教えて...
-
HTMLソースからURLだけを抜き出...
-
リンクのクリック数を把握したい
-
bodyにidをつける理由は何ですか?
-
submitボタンで他のフレームを...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
function の return 値を表示し...
-
SCRIPT5007: 未定義または NULL...
-
JavaScriptでiframeの内容を「...
-
getElementsByNameで要素が取得...
-
キーを押している間の時間を計...
-
フォーカス移動抑止について
-
JavaScriptでの西暦下2桁での表...
-
自動ジャンプでフォームデータ...
-
出荷予定日を表示するJavaスク...
-
クリックすると別の文章を表示する
-
リンク移動先のURLを取得
-
乱数を一定時間毎に表示させた...
-
JavaScript でキーを送る
-
idHOGEで取得したinnerText(数...
-
ボタンのID名を取得するには?
-
htaでVBSのソースを書いたらエ...
-
Javascriptの出力結果をhtmlボ...
-
bodyタグのfocus
-
AjaxでDBから取得したデータを...
-
JavaScriptでのEnterキーとAlt+...
おすすめ情報