使用Google Maps Javascript API v3
Geoprer将地址转换为可以在地图上显示的坐标。
<html><head><meta name="viewport" content="initial-scale=1.0, user-scalable=no"/><meta http-equiv="content-type" content="text/html; charset=UTF-8"/><title>Google Maps Javascript API v3 Example: Geocoding Simple</title><script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><script type="text/javascript"> var geoprer; var map; var address ="San Diego, CA"; function initialize() { geoprer = new google.maps.Geoprer(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); if (geoprer) { geoprer.geopre( { 'address': address}, function(results, status) { if (status == google.maps.GeoprerStatus.OK) { if (status != google.maps.GeoprerStatus.ZERO_RESULTS) { map.setCenter(results[0].geometry.location); var infowindow = new google.maps.InfoWindow( { content: '<b>'+address+'</b>', size: new google.maps.Size(150,50) }); var marker = new google.maps.Marker({ position: results[0].geometry.location, map: map, title:address }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } else { alert("No results found"); } } else { alert("Geopre was not successful for the following reason: " + status); } }); } }</script></head><body onload="initialize()"> <div id="map_canvas" ></body></html>工作代码段:
var geoprer;var map;var address = "San Diego, CA";function initialize() { geoprer = new google.maps.Geoprer(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, navigationControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); if (geoprer) { geoprer.geopre({ 'address': address }, function(results, status) { if (status == google.maps.GeoprerStatus.OK) { if (status != google.maps.GeoprerStatus.ZERO_RESULTS) { map.setCenter(results[0].geometry.location); var infowindow = new google.maps.InfoWindow({ content: '<b>' + address + '</b>', size: new google.maps.Size(150, 50) }); var marker = new google.maps.Marker({ position: results[0].geometry.location, map: map, title: address }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); } else { alert("No results found"); } } else { alert("Geopre was not successful for the following reason: " + status); } }); }}google.maps.event.addDomListener(window, 'load', initialize);html,body,#map_canvas { height: 100%; width: 100%;}<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><div id="map_canvas" ></div>


