google map 根据坐标点自动缩放
2015-12-07 14:56
381 查看
google map v3的命令和v2有些差别。下面把我的代码贴出来。
这个功能主要是如果一个地图上有多个坐标,可以根据坐标点自动计算zoom值,防止有点坐标点跑到地图外面,导致显示不全。
<script type="text/javascript" src="http://ditu.google.cn/maps/api/js?v=3.exp&key=xxxxxxxx&language=zh-cn&sensor=false"></script>
planService.initMap = function (id, flightPlanCoordinates, areaList) { // by sjw
var lat = 34.0204989; //默认坐标点
var lng = -118.4117325; //默认坐标点
var map = new google.maps.Map(document.getElementById('map' + id), {
zoom: 6, //默认zoom=6
center: {lat: lat, lng: lng},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var bounds = new google.maps.LatLngBounds(); //声明一个bounds
$.each(areaList, function (i, area) { //遍历坐标列表
var image = '../../resources/images/icon-' + area.imgName + '.png'; //声明图标
bounds.extend(new google.maps.LatLng(area.lat, area.lng));
var beachMarker = new google.maps.Marker({
position: {lat: area.lat, lng: area.lng},
map: map,
icon: image
});
})
if (areaList.length > 1) { //如果坐标点多余1个,则使用 google map 的fitBounds,自动计算zoom值
map.fitBounds(bounds);
}
var lineSymbol = { //把各点用虚线连起来
path: 'M 0,-1 0,1',
strokeOpacity: 1,
strokeWeight: 2, //线粗细
scale: 2 //虚线段长度
};
var line = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeOpacity: 0,
strokeColor: "#ed5565", //颜色
strokeWeight: 1,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '15px' //间距
}],
map: map
});
};
这个功能主要是如果一个地图上有多个坐标,可以根据坐标点自动计算zoom值,防止有点坐标点跑到地图外面,导致显示不全。
<script type="text/javascript" src="http://ditu.google.cn/maps/api/js?v=3.exp&key=xxxxxxxx&language=zh-cn&sensor=false"></script>
planService.initMap = function (id, flightPlanCoordinates, areaList) { // by sjw
var lat = 34.0204989; //默认坐标点
var lng = -118.4117325; //默认坐标点
var map = new google.maps.Map(document.getElementById('map' + id), {
zoom: 6, //默认zoom=6
center: {lat: lat, lng: lng},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var bounds = new google.maps.LatLngBounds(); //声明一个bounds
$.each(areaList, function (i, area) { //遍历坐标列表
var image = '../../resources/images/icon-' + area.imgName + '.png'; //声明图标
bounds.extend(new google.maps.LatLng(area.lat, area.lng));
var beachMarker = new google.maps.Marker({
position: {lat: area.lat, lng: area.lng},
map: map,
icon: image
});
})
if (areaList.length > 1) { //如果坐标点多余1个,则使用 google map 的fitBounds,自动计算zoom值
map.fitBounds(bounds);
}
var lineSymbol = { //把各点用虚线连起来
path: 'M 0,-1 0,1',
strokeOpacity: 1,
strokeWeight: 2, //线粗细
scale: 2 //虚线段长度
};
var line = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeOpacity: 0,
strokeColor: "#ed5565", //颜色
strokeWeight: 1,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '15px' //间距
}],
map: map
});
};
相关文章推荐
- Intent中的四个重要属性——Action、Data、Category、Extras
- 解决Toast不显示问题 Toast invisible to user . go ahead
- Google Guava 常用功能
- go语言 defer 你不知道的秘密!
- Go语言使用PostgreSQL数据库
- go中的闭包
- Go语言中使用SQLite数据库
- Go语言中使用MySql数据库
- 一个Ip2long函数,通过调用go tool pprof分析,竟发现内存分配了3G
- Scrambled Polygon(凸多边形,斜率)
- Link-state routing algorithm simulation
- HDU 3966 Aragorn's Story(树链剖分+线段树)
- Golang安装
- BestCode_Round65_C题(线段树)
- 理解Golang包导入
- Django Generic Display View
- golang---利用反射机制对结构体进行循环赋值
- django最简单表单入门
- Google Play 2015年度最佳游戏与应用公布
- Google Play 2015年度最佳游戏与应用公布