<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MapTest6.aspx.cs" Inherits="MapTest6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>V3 版本 根据地理名称定位</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(39.904667, 116.408198);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
//获得地址并回传
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
//创建标记
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("地理编码没有成功,原因如下: " + status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div>
<input id="address" type="text" value="北京 方庄">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map_canvas" style="height:90%"></div>
</body>
</html>
这段代码是把 要查询的地址写在前台文本框的,你可以让文本框的值从后面传过来
引用其他地图的API?51ditu的比较简单,记得两三句话就能引用到一个地图。