日期:2014-05-17  浏览次数:20687 次

Google Map和HTML5定位和动态加载
动态加载!
<script>
function loadScript() {
			var script = document.createElement("script");  
			script.type = "text/javascript";
			script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=getGeoLocation";  
			document.body.appendChild(script);  
};
function getGeoLocation(){
	if(navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(function(position) {
			var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
			console.log("position.coords.latitude:"+position.coords.latitude+"   position.coords.longitude:"+position.coords.longitude);
			var myOptions = {
				zoom: 15,
				center: point,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			
			var mapDiv = document.getElementById("rescue-map");
			var map = new google.maps.Map(mapDiv, myOptions);
			
			var marker = new google.maps.Marker({
				position: point,
				map: map,
				title: "You are here"
			});
		});
	}
}
window.onload = loadScript;
<script>
<div id="rescue-map" ></div>