封装的google地图几个常用方法
来源:互联网 发布:access2007数据库教程 编辑:程序博客网 时间:2024/05/22 04:25
包含地图初始化,添加标记,画线,取点的坐标等方法
<script src="http://maps.googleapis.com/maps/api/js?key=[you register key]&sensor=false"></script><div class="map"></div><script type="text/javascript"> $(function () { var myMap; var cars = {}; var ico = '/img/car.ico'; var minZoom = 8; var maxZoom = 16; function init() { //初始化地图 var mapOptions = { zoom: 10, center: new google.maps.LatLng(29.872885, 121.552809),//中心点 mapTypeId: google.maps.MapTypeId.ROADMAP, } myMap = new google.maps.Map(document.getElementById("map"), mapOptions); //控制缩放级别 google.maps.event.addListener(myMap, 'zoom_changed', function () { if (myMap.getZoom() < minZoom) { myMap.setZoom(minZoom); } if (myMap.getZoom() > maxZoom) { myMap.setZoom(maxZoom); } }); } function addMarkers(points) { for (var i = 0; i < points.length; i++) { addMarker(points[i]); } } function addMarker(p) { var o = cars[p.id]; o && o.setMap(null); cars[p.id] = new google.maps.Marker({ map: myMap, icon: ico, title: p.name, status: 'active', position: new google.maps.LatLng(p.x, p.y) }); } init(); //画线 var linePoints = [ new google.maps.LatLng(29.83092, 121.55923), new google.maps.LatLng(29.83020, 121.55923), new google.maps.LatLng(29.83015, 121.56059), new google.maps.LatLng(29.82929, 121.56423), new google.maps.LatLng(29.82276, 121.56407), new google.maps.LatLng(29.82273, 121.56652), new google.maps.LatLng(29.82234, 121.56652), new google.maps.LatLng(29.82209, 121.56695), ]; var trackPath = new google.maps.Polyline({ path: linePoints, strokeColor: "#FF0000", // 线条颜色 strokeOpacity: 1.0, // 线条透明度 strokeWeight: 2 // 线条粗细 }); trackPath.setMap(myMap); //画线 //右键取当前点的坐标 google.maps.event.addListener(myMap, "rightclick", function(event) { var lat = event.latLng.lat(); var lng = event.latLng.lng(); // 经纬度 alert("Lat=" + lat + "; Lng=" + lng); }); //添加标记 var list = [ { id: 1, x: 29.761246, y: 121.546600, name: 'driver 1' }, { id: 2, x: 29.891246, y: 121.566600, name: 'driver 1' }, ]; addMarkers(list); });</script>
阅读全文
0 0
- 封装的google地图几个常用方法
- js常用的几个方法封装
- Android关于百度地图开发的几个常用方法
- google地图的简易封装(一)
- 常用的封装方法
- 几个常用的方法
- 百度地图几个常用的鼠标事件
- 解析xml几个方法的简单封装
- 封装几个操作数据库的方法SqlHelper
- 常用ajax封装的方法
- iOS常用的封装方法
- 常用js方法的封装
- iOS封装常用的方法
- Selenium常用方法的封装
- 几个java常用的方法
- inventDimParm 常用的几个方法
- JFrame常用的几个方法
- js几个常用的方法
- MFC文档/视图结构关联基类学习
- mybatis如何防止sql注入
- 【深度学习】caffe之SGD solver
- caffe 中 top_data, top_label 的存储方式
- Making Sense of all these Crazy Web Service Standards
- 封装的google地图几个常用方法
- LaTex 学习入门
- Java API源码阅读邀请
- bzoj1270: [BeijingWc2008]雷涛的小猫
- kafka等,今天面试了
- (css3常用动画的实现
- 总结 2017-12-15
- JNI开发基础篇:Java类调用C库或者方法
- FFmpeg && nginx (centos 7)