【发布时间】:2016-02-18 06:23:42
【问题描述】:
我有一个使用 google maps api 开发的 web 应用程序我想旋转图形,如第二张图片所示我尝试从 google api 为该中心旋转 45 度的示例:{lat:1.349992, lng:103.985374}, value there is no title for this location 表示什么, 而当我集成示例应用程序时,在集成旋转之前没有显示在浏览器原始地图中
需要的输出是(基本上需要直接显示) 我实现功能的代码如下所示
<!DOCTYPE html>
<html>
<head lang="en">
<style>
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#map {
height: 100%;
}
#floating-panel {
position: absolute;
top: 10px;
left: 25%;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
text-align: center;
font-family:'Roboto', 'sans-serif';
line-height: 30px;
padding-left: 10px;
}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script>
<script>
var markers = [ {
"title": 'point4',
"lat": '1.355333',
"lng": '103.987305',
"description": 'uuu'
}, {
"title": 'point3',
"lat": '1.354432',
"lng": '103.987262',
"description": 'zzz'
}, {
"title": 'point3',
"lat": '1.353199',
"lng": '103.986908',
"description": 'zzz'
}
];
var colorVariable = ["green", "blue", "yellow", "rose"];
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
heading: 90,
tilt: 45
};
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var infoWindow = new google.maps.InfoWindow();
var lat_lng = new Array();
var latlngbounds = new google.maps.LatLngBounds();
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
lat_lng.push(myLatlng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
latlngbounds.extend(marker.position);
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
function rotate90() {
var heading = map.getHeading() || 0;
map.setHeading(heading + 90);
}
function autoRotate() {
window.setInterval(rotate90, 3000);
}
//Loop and Draw Path Route between the Points on MAP
for (var i = 0; i < lat_lng.length; i++) {
if ((i + 1) < lat_lng.length) {
var src = lat_lng[i];
var des = lat_lng[i + 1];
getDirections(src, des, colorVariable[i], map);
}
}
}
function getDirections(src, des, color, map) {
//Intialize the Direction Service
var service = new google.maps.DirectionsService();
service.route({
origin: src,
destination: des,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
//Intialize the Path Array
var path = [];
for (var i = 0; i < result.routes[0].overview_path.length; i++) {
path.push(result.routes[0].overview_path[i]);
}
//Set the Path Stroke Color
var polyOptions = {
strokeColor: color,
strokeOpacity: 1.0,
strokeWeight: 8,
path: path,
map: map
}
poly = new google.maps.Polyline(polyOptions);
poly.setMap(map);
}
});
}
</script>
</head>
<body>
<div id="floating-panel">
<input type="button" value="Auto Rotate" onclick="autoRotate();"></div>
<div id="dvMap"></div>
</body>
</html>
请指出我哪里出错了
【问题讨论】:
-
谢谢你,我是一个发布这个问题的人,我已经整合了这些变化,之后我得到了这个我正在尝试检查可能是什么问题
-
问题(正如我在回答中评论的那样)是该位置没有空中瓷砖。这意味着 google maps javascript API v3 不会为您进行任何轮换。
-
谁能说这是否可以在任何其他 api (如地图框)中做到这一点
标签: javascript google-maps google-maps-api-3 rotation