<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=zh-CN"></script> <!--google 拉框控件--> <script type="text/javascript" src="keydragzoom.js"></script> </HEAD> <BODY onload='init()'> <div id='gmap' style="width: 800px; height: 600px"> </div> <script> var latlng=[[31.840650970233095,117.19356549365238], [31.83525511970765,117.18498242480473], [31.84524448619277,117.18000424487309], [31.849546142939282,117.19356549365238]]; var bounds=[[31.845973594676078,117.18026173693852], [31.83897391535159,117.16944707019047]] function log(str){ document.getElementById('a').innerHTML=document.getElementById('a').innerHTML+"</br>"+str; } function mapControl(){ this.control; this.infoWindwo; this.geoCoder; this.points=[]; //标点集合对象 this.polyLine=null; //轨迹线对象 this.polyGon=null; //多边形 this.rectangle=null; //矩形 this.circle=null; //圆形 this.overlayView=null; //气泡框 this.gEvent=function (){return google.maps.event;}; //google事件对象 var temp=this; this.mapStyle=new function (){ //将地图的中心设置为指定的地理点 可以使用 0(最低缩放级别,在地图上可以看到整个世界)到 19(最高缩放级别,可以看到独立建筑物)之间的缩放级别 //ROADMAP-默认视图 SATELLITE-显示Google地球卫星图像 HYBRID-混合显示普通视图和卫星视图 TERRAIN-地形图 this.hybrid=google.maps.MapTypeId.HYBRID; //混合 this.roadmap=google.maps.MapTypeId.ROADMAP; //路线图 this.satellite=google.maps.MapTypeId.SATELLITE; //卫星 this.terrain=google.maps.MapTypeId.TERRAIN; //地形 } this.mapMenuStyle=new function (){ this.defaultMenu =google.maps.MapTypeControlStyle.DEFAULT; //默认样式 HORIZONTAL_BAR this.dropdownMenu =google.maps.MapTypeControlStyle.DROPDOWN_MENU; //位置 this.horizontalBar =google.maps.MapTypeControlStyle.HORIZONTAL_BAR; //风格 } this.geocoderStatus=new function (){ //google.maps.GeocoderStatus; this.error= google.maps.GeocoderStatus.ERROR; //There was a problem contacting the Google servers. this.invalidRequest= google.maps.GeocoderStatus.INVALID_REQUEST; //This GeocoderRequest was invalid. this.ok= google.maps.GeocoderStatus.OK; //The response contains a valid GeocoderResponse. this.overQueryLimit= google.maps.GeocoderStatus.OVER_QUERY_LIMIT; //The webpage has gone over the requests limit in too short a period of time. this.requestDenied= google.maps.GeocoderStatus.REQUEST_DENIED; //The webpage is not allowed to use the geocoder. this.unknownError= google.maps.GeocoderStatus.UNKNOWN_ERROR; //A geocoding request could not be processed due to a server error. The request may succeed if you try again. this.zeroResults= google.maps.GeocoderStatus.ZERO_RESULTS; } this.initialize=function () { //google.maps.MapTypeControlStyle.DROPDOWN_MENU var mapOptions = { zoom: 14, //缩放级别 center: new google.maps.LatLng(31.838463501293745, 117.17588437182617), mapTypeId: temp.mapStyle.terrain, scaleControl: true, //比例尺 mapTypeControl: true, mapTypeControlOptions: {style: temp.mapMenuStyle.dropdownMenu} }; temp.control = new google.maps.Map(document.getElementById("gmap"),mapOptions);//编写 JavaScript 函数创建“map”对象 //按shift拉框 temp.control.enableKeyDragZoom({ key: "shift", boxStyle: { border: "4px dashed black", backgroundColor: "transparent", opacity: 1.0 }, veilStyle:{ backgroundColor: "red", opacity: 0.35, cursor: "crosshair" } }); //拉框返回事件 var dz = temp.control.getDragZoomObject(); //按下shift后的事件 //google.maps.event.addListener(dz, 'activate', function () {log('KeyDragZoom Activated');}); //shift弹起后的事件 //google.maps.event.addListener(dz, 'deactivate', function () {log('KeyDragZoom Deactivated');}); //google.maps.event.addListener(dz, 'dragstart', function (latlng) {log('KeyDragZoom Started: ' + latlng);}); //拉动时的经纬度 //google.maps.event.addListener(dz, 'drag', function (startPt, endPt) {log('KeyDragZoom Dragging: ' + startPt + endPt);}); //最后的经纬度 google.maps.event.addListener(dz, 'dragend', function (bnds) { temp.createRectangle(bnds) log('KeyDragZoom Ended: ' + bnds); }); //点击地图创建点 google.maps.event.addListener(temp.control, 'click', function(event) { temp.clearAllMapMarker(); //temp.getAddrsText(event.latLng) temp.addPoint(event.latLng) log(event.latLng.lat()+":"+event.latLng.lng()); }); temp.geoCoder=temp.getGeoCoder(); temp.infoWindwo=temp.getInfoWindow(); //画线 var xys1=[]; var xys2=[]; for(var i in latlng){ var xy= temp.createLatLng(latlng[i][0],latlng[i][1]); xys1.push(xy); xys2.push(xy) } //temp.createPolyLine(xys1); xys2.push(xys2[0]) //temp.createPolyGon(xys2); var xys3=[]; for (var i in bounds ) { var xy= temp.createLatLng(latlng[i][0],latlng[i][1]); xys3.push(xy) } //temp.createRectangle(temp.createLatLngBounds(xys3[0],xys3[1])) temp.createCircle(xys3[0],1000); } //创建一个经纬度对象 this.createLatLng=function (lat,lng){ return new google.maps.LatLng(lat,lng); } //矩形大小对象 this.createLatLngBounds=function (lb,rt){ return new google.maps.LatLngBounds(rt,lb); } this.getPointOption=function (){ google.maps.MarkerOptions.call(this); return this; } this.getLatLng=function (LatLng){ return new google.maps.LatLng(LatLng); } //创建默认标点 this.addPoint=function (latLng){ //var option =temp.getPointOption(); var markerLatLng = temp.getLatLng(latLng); var point=new google.maps.Marker({ position: latLng, map: temp.control }); temp.points.push(point); temp.control.setCenter(latLng); temp.gEvent().addListener(point, "click", function(){ temp.animation(point); temp.infoWindwo.open(temp.control,point); }); } //创建图片标点 this.addImagePoint=function (latLng){ //MarkerImage(url:string, size?:Size, origin?:Point, anchor?:Point, scaledSize?:Size) } //动画类 this.animation=function (marker){ //google.maps.Animation if (marker.getAnimation() != null) { marker.setAnimation(null); } else { marker.setAnimation(google.maps.Animation.BOUNCE);//跳跃 } } //获取poi信息 this.getAddrsText=function (latLng){ temp.geoCoder.geocode({'location': latLng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var address; address = results[0].formatted_address; alert(address); } else { alert("Geocoder failed due to: " + status); } } }); } //画线 this.createPolyLine=function (latLngs){ temp.polyLine=new google.maps.Polyline({ path:latLngs, map: temp.control }); } //画多边形 this.createPolyGon=function (latLngs){ //google.maps.Polygon; temp.polyGon=new google.maps.Polygon({ path:latLngs, map: temp.control }); } //画矩形 this.createRectangle=function (bound){ temp.rectangle=new google.maps.Rectangle({ bounds:bound, map: temp.control }); } //画圆形 this.createCircle=function (latLng,radiu){ //google.maps.Circle temp.circle=new google.maps.Circle({ map: temp.control, center:latLng, radius:radiu }); } //位置信息对象 this.getGeoCoder=function (){ return new google.maps.Geocoder(); } //气泡框 this.createOverlayView=function (){ return new google.maps.OverlayView(); } this.getInfoWindow=function (){ return new google.maps.InfoWindow( { size: new google.maps.Size(50,50), map:temp.control, content: "I'm here!" //position: location }); } this.clearAllMapMarker=function (){ if(temp.points!=null && temp.points.length>0){ for(var i in temp.points){ temp.points[i].setMap(null); }; temp.points=[]; }; //temp.infoWindwo.close(); } } function init(){ var a=new mapControl(); a.initialize(); } </script> <div id='a'> </div> </BODY> </HTML>
详细解决方案
google V3 简略实用
热度:520 发布时间:2012-06-26 10:04:13.0
相关解决方案
- google map有关问题
- GWT 报错,能的请进: com.google.gwt.event.shared.UmbrellaException: Exception caught: Se
- google chrome浏览器中 查看框架的源代码,具体是干吗用的,为什么有些网页有这个选项,有些没有
- Google APi可以获取一个地址的所在商圈吗 ,也许百度Map api的java,php调用方法
- 关于 google map 经度和纬度的有关问题
- Google Maps v3 中交通的有关问题
- google.com进不去的时候解决方法。 散分
- 想开发一套基于GPS+GPRS+Google 地图的车辆管理系统,该如何做
- java.net.UnknownHostException: www.google.com.hk,该怎么处理
- google map api key 如何获得
- google、百度的查询速度如此之快,而且并发数这么大,如何做到的
- SQLite.NET 找不到表, Google 了良久了都不行
- javascript取有点网页的html元素的offsetLeft,offsetTop数据不准,比如http://www.google.com.hk/
- Google App Engine 可以筹建IIS开发环境访问吗
- asp.net+google 地图 api
- google 地图不能在form里边显示
- Google 电子凭栏矩形拉框对象一直没找到!
- https google maps不显示,该如何处理
- google map api 动态反向地址解析,该怎么处理
- 搜索引擎(百度,google)接受cookie吗?不是登陆是一般的参数保存。主要是网页收录会不会受影响解决方法
- :小弟我的网站上不少 aspx 页面上都被人强行嵌入了 google 的广告代码,现在用什么方法补救呢?万分感谢
- 类似 google adsense 技术,源代码,本人想开发这样的程序,希望大家多多留言,解决思路
- google checkout 401 erro解决办法
- 编程有时要借助baidu,google,csdn的帮助,正常吗?解决办法
- 散分讨论:是不是 腾讯QQ技术 比 GOOGLE 还牛?解决办法
- google suggest 的有关问题: 输入提醒后, span为什么隐藏不了呢
- GOOGLE,BAIDU对伪装aspx的URL网页收录如何样?和html相比!(顶者有分)
- google 是什么页面?该如何解决
- 有高手用过 Google Checkout吗?解决办法
- 今天面试题目:百度,GOOGLE,搜狐,网易,新浪使用什么数据库?该如何处理