当前位置: 代码迷 >> JavaScript >> 预览稿件: 初学 Google Maps JavaScript (5) 画圆指定范围
  详细解决方案

预览稿件: 初学 Google Maps JavaScript (5) 画圆指定范围

热度:358   发布时间:2012-11-06 14:07:00.0
预览文章: 初学 Google Maps JavaScript (5) 画圆指定范围

<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no;">
<meta charset="utf-8" />
<script src="http://maps.google.com/maps/api/js?sensor=false&language=zh"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<style>#map{width:100%;height:100%}.info{font-size:14px}</style>
<script>
var latlng=marker=circle=geocoder=infowindow=map=address=null;
$.LatLng = function(lat,lng){
	return new google.maps.LatLng(lat,lng);
}
$.Marker = function(opts){
	return new google.maps.Marker(opts);
}
$.InfoWindow = function(opts){
	return new google.maps.InfoWindow(opts);
}
$.Circle = function(opts){
	return new google.maps.Circle(opts);
}
$.Geocoder = function(){
	return new google.maps.Geocoder();
}
$(function(){	
	$.getJSON('gLatlng.php',{jz:'基站信息'},function(d){
		latlng = $.LatLng(d.lat,d.lng)
		map = new google.maps.Map($('#map')[0],{
				zoom:8,
				center:latlng,
				mapTypeId:google.maps.MapTypeId.ROADMAP
			});
		marker=$.Marker({position:latlng,map:map,icon:"1.png",draggable:true});
		circle=$.Circle({
			strokeColor: "#86ACDE",
			strokeOpacity: 0.8,
			strokeWeight: 2,
			fillColor: "#DCE2EA",
			fillOpacity: 0.7,
			map: map,
			center: latlng,
      		radius: 35000
		});
		infowindow = $.InfoWindow();
		geocoder = $.Geocoder();
		geocoder.geocode({'latLng':latlng},function(results,status){
			if(geocoder){
				if(status==google.maps.GeocoderStatus.OK){
					infowindow.setContent('<span class="info">'+results[0].formatted_address+'</span>');
				}
				else{
					alert(status);
				}
			}
		});
		infowindow.open(map,marker);
		google.maps.event.addListener(marker,"click",function(){
			infowindow.open(map,marker);
		});
		google.maps.event
	}); 
});
</script>
</head>
<body>
	<div id="map"></div>
</body>
</html>
  相关解决方案