zoukankan      html  css  js  c++  java
  • Google Maps Application Developing —— Search Address

     
    <script type="text/javascript">
    (function(){
    	var map, geocoder, marker, infowindow;
    
    	window.onload = function(){
    		
    		var mapOptions = {
    			zoom:14,
    			center:new google.maps.LatLng(39.9, 116.4),
    			mapTypeId:google.maps.MapTypeId.ROADMAP
    		};
    
    		map = new google.maps.Map(document.getElementById('map'), mapOptions);
    
    		var form = document.getElementById('addressForm');
    
    			form.onsubmit = function(){
    			var address = document.getElementById('address').value;
    
    			getCoordinates(address);
    
    			return false;
    		}
    	}
    
    function getCoordinates(address){
    	if(!geocoder){
    		geocoder = new google.maps.Geocoder();
    	}
    
    	var geocoderRequest = {address:address}
    		
    	geocoder.geocode(geocoderRequest, function(results, status){
    		if(status == google.maps.GeocoderStatus.OK){
    			map.setCenter(results[0].geometry.location);
    
    			if(!marker){
    				marker = new google.maps.Marker({map:map});
    			}
    			marker.setPosition(results[0].geometry.location);
    
    			if(!infowindow){
    				infowindow = new google.maps.InfoWindow();
    			}
    
    			var content = '<strong>' + results[0].formatted_address + 
    					'</strong><br/>';
    			content += '纬度: ' + results[0].geometry.location.lat() + '<br/>';
    			content += '经度: ' + results[0].geometry.location.lng();
    
    			infowindow.setContent(content);
    
    			infowindow.open(map, marker);
    		}
    	});
    }
    })();

    作者:Create Chen
    出处:http://technology.cnblogs.com
    说明:文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
    知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

  • 相关阅读:
    构建之法阅读笔记02
    4.7-4.13 第八周总结
    构建之法阅读笔记01
    顶会热词统计
    结对作业-四则运算升级版
    3.31-4.5 第七周总结
    大道至简阅读笔记03
    3.23-3.30 第六周总结
    第7周总结
    人月神话阅读笔记之三
  • 原文地址:https://www.cnblogs.com/technology/p/2330769.html
Copyright © 2011-2022 走看看