我从here获得了Google地图中绘制折线的代码 但我希望根据纬度和经度将重点放在地图上,所以我添加了这一行 - > map.setCenter(new google.maps.LatLng(-122.5868225097656,45.56117947133065)); 但是折线没有出现,因为纬度和经度在屏幕之外,我添加的线(map.setCenter)没有改变任何东西 这是代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script>
function initialize() {
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0, -180),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
map.setCenter(new google.maps.LatLng(-122.5868225097656,45.56117947133065));
var flightPlanCoordinates = [
new google.maps.LatLng(-122.5868225097656,45.56117947133065),
new google.maps.LatLng(-122.6348876953125,45.493833740092185)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
答案 0 :(得分:1)
-122.5868225097656,45.56117947133065
-122.6348876953125,45.493833740092185
是无效的latlong(s)。这就是app无法正常工作的原因。
我试图交换价值观。工作得很好。
map.setCenter(new google.maps.LatLng(45.56117947133065,-122.5868225097656));
var flightPlanCoordinates = [
new google.maps.LatLng(45.56117947133065,-122.5868225097656),
new google.maps.LatLng(45.493833740092185,-122.6348876953125)
];