Google maps api v3 需要key 吗?求大神指导!

yang珂 发布于 2012/07/23 16:57
阅读 1K+
收藏 0
Google maps api v3 需要key  吗?求大神指导!  用 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>  怎么加载不出来啊 !v3 还是需要key 吗?

加载中
0
情天大圣
情天大圣
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
	<link rel="stylesheet" type="text/css" href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" />
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <style type="text/css">
		#control {
			background: #fff;
			padding: 5px;
			font-size: 14px;
			font-family: Arial;
			border: 1px solid #ccc;
			box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);
			display: none;
		}
	</style>
	<title>Google Map</title>
	<script type="text/javascript">
		var map;
		var marker;
		var geocoder;
		var markerArr = [];
		var infowindowArr = [];
		
		function init() {
			geocoder = new google.maps.Geocoder();
			var myLatlng = new google.maps.LatLng(22.5329870, 113.9304440);
			var myOptions = {
				zoom : 12,
				center : myLatlng,
				mapTypeId : google.maps.MapTypeId.ROADMAP
			};
			map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
			var control = document.getElementById("control");
			control.style.display = "block";
			map.controls[google.maps.ControlPosition.TOP].push(control);
	
			var markerTo = new google.maps.Marker();
	
			google.maps.event.addListener(map, 'click', function(event) {
				clearOverLays();
				markerTo.setOptions({
					position : event.latLng,
					map : map
				});
				startSearchByLatlng(event.latLng);
			});
		}
		
		function startSearchByAddress() {
			var address = document.getElementById("address").value;
			clearOverLays();
			if (geocoder) {
				geocoder.geocode({
					'address' : address
				}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						addMarker(results[0].geometry.location);
						parent.document.getElementById("location").value = results[0].formatted_address;
					} else {
						alert(status);
					}
				});
			}
		}
	
		function startSearchByLatlng(location) {
			clearOverLays();
			if (geocoder) {
				geocoder.geocode({
					'latLng' : location
				}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						addInfowindow(location, results[0].formatted_address);
					} else {
						alert(status);
					}
				});
			}
		}
		
		function clearOverLays() {
			if (markerArr) {
				for (i in markerArr) {
					markerArr[i].setMap(null);
				}
				markerArr.length = 0;
			}
			if (infowindowArr) {
				for (i in infowindowArr) {
					infowindowArr[i].setMap(null);
				}
				infowindowArr.length = 0;
			}
		}
		
		function addMarker(location) {
			var marker = new google.maps.Marker({
				position : location,
				map : map
			});
			markerArr.push(marker);
		}
		
		function addInfowindow(location, address) {
			var infowindow = new google.maps.InfoWindow();
			infowindow.setPosition(location);
			infowindow.setContent("纬度:" + location.lat() + "<br/>经度:" + location.lng() + "<br/>地点:" + address);
			infowindow.open(map);
	
			infowindowArr.push(infowindow);
			
			parent.document.getElementById("location").value = address;
			parent.document.getElementById("latitude").value = location.lat();
			parent.document.getElementById("longitude").value = location.lng();
		}
	</script>
</head>

<body onload="init();">
	<div id="control">
		<input type="text" value="广东省深圳市福田区" id="address" />
		<input type="button" onclick="startSearchByAddress();" value="搜索" />
	</div>
	
	<div id="map_canvas" style="width: 100%; height: 100%"></div>
</body>
</html>
0
yingouqlj
yingouqlj
好像不需要啊..   你只载入了一个文件吧... 没初始化地图.
yang珂
yang珂
回复 @情天大圣 : 哦哦!谢拉!
情天大圣
情天大圣
回复 @yang珂 : 我代码都贴了,晕!
yang珂
yang珂
哦!那初始化地图怎么弄的 啊!谢谢!
0
♬Windchaser
♬Windchaser
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google maps API</title>

    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAoYmFz4qUoRdMHm5A0fSxhBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSGi5oF_DGiTdrk-IhErWWFlfOe7w"></script>
<!--导入Google Maps API库文件。-->
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAoYmFz4qUoRdMHm5A0fSxhBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSGi5oF_DGiTdrk-IhErWWFlfOe7w" type="text/javascript"></script>

<script type="text/javascript">

Google maps api v2 是需要key验证的,我想v3也是需要验证的吧

 

♬Windchaser
♬Windchaser
两年多没搞js,受教了
情天大圣
情天大圣
V3不需要!
返回顶部
顶部