Android - Google Map APIv3-地圖Marker與路線規劃

  • 6427
  • 0

摘要:Android - Google Map APIv3-地圖Marker與路線規劃

Marker 設定與訊息視窗

加入mark function並叫用


//標籤
	function mark() {
		var myLatLng = new google.maps.LatLng(22.646938, 120.611363);
		var myMarker = new google.maps.Marker({
			position : myLatLng,
			map : map,
		});

		//訊息視窗
		var content = "訊息視窗!!!!";
		var infowindow = new google.maps.InfoWindow({
			content : content
		});
		google.maps.event.addListener(myMarker, 'click', function() {
			infowindow.open(map, myMarker);
		});
	}
	

完成畫面

 

 

路線規劃

加入RoutePlanning function並叫用


//路線規劃
	var directionsDisplay;
	var directionsService = new google.maps.DirectionsService();//路線資訊回傳

	function RoutePlanning() {
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsDisplay.setMap(map);

		var start = "國立屏東科技大學";
		var point1="屏東縣內埔鄉廣濟路14號";
		var point2="屏東縣內埔鄉廣濟路64號";
		var end = "屏東縣內埔鄉廣濟路164號"

		var request = {
			origin : start,
			//中間點
			waypoints : [ {
				location : point1,
				stopover : true
			}, {
				location : point2,
				stopover : true
			} ],
			destination : end,
			travelMode : google.maps.DirectionsTravelMode.DRIVING
		};

		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			}
		});
	}
	

 

完成畫面

 

完整程式碼 GoogleMAPv3_2.zip