Google Map API怎么根据地址获得经纬度
1个回答
展开全部
可以看看这个代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetLatLng.aspx.cs" Inherits="WebUI.GetLatLng" %>
<!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 runat="server">
<title>地理位置坐标转换-根据地址查询出经纬度</title>
<script src="http://ditu.google.cn/maps?file=api&v=2&key=your key&sensor=true"
type="text/javascript"></script>
<script type="text/javascript">
window.g = {};
window.$ = function(id) { return document.getElementById(id) };
window.onload = function() {
if (GBrowserIsCompatible()) {
g.map = new GMap2($("map"));
g.map.addControl(new GLargeMapControl());
g.map.addControl(new GMapTypeControl());
g.map.addControl(new GScaleControl());
g.geocoder = new GClientGeocoder();
g.getCoordinates = function(address) {
g.geocoder.getLatLng(
address,
function(point) {
if (point) {
g.map.setCenter(point, 13);
var marker = new GMarker(point);
g.map.addOverlay(marker);
var info = "<strong>" + address + "&
lt;/strong><br />坐标: 纬度=" + point.lat() + ",经度=" + point.lng();
$("info").innerHTML = info;
marker.openInfoWindowHtml(info);
marker.__address_info = info;
GEvent.addListener(marker, "click", function() {
g.map.setCenter(this.getLatLng());
this.openInfoWindowHtml(this.__address_info);
$("info").innerHTML = info;
});
}
else {
alert("无法解析: " + address);
}
}
)
}
$("btn_go").onclick = function() {
g.getCoordinates($("address").value);
}
$("btn_go").onclick();
}
else {
alert('不支持的浏览器');
}
}
window.onunload = function() {
GUnload();
}
</script>
<style media="screen">
body
{
margin: 0;
padding: 0;
font-size: 9pt;
line-height: 1.5em;
}
#frame
{
width: 700px;
margin: 20px auto 10px;
}
#form
{
margin: 0 0 10px;
text-align: center;
}
#form input
{
border: 1px solid #ccc;
font-size: 9pt;
width: 200px;
}
#form button
{
font-size: 9pt;
border: 1px solid #ccc;
}
#form button:hover
{
background: #eef;
}
#map
{
height: 400px;
margin: 0 0 10px;
border: 5px solid #ccc;
}
</style>
</head>
<body>
<div id="frame">
<div id="form">
输入一个地址:
<input id="address" value="上海市浦东新区张江镇" />
<button id="btn_go">
获取坐标</button>
</div>
<div id="map">
</div>
<div id="info">
</div>
</div>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetLatLng.aspx.cs" Inherits="WebUI.GetLatLng" %>
<!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 runat="server">
<title>地理位置坐标转换-根据地址查询出经纬度</title>
<script src="http://ditu.google.cn/maps?file=api&v=2&key=your key&sensor=true"
type="text/javascript"></script>
<script type="text/javascript">
window.g = {};
window.$ = function(id) { return document.getElementById(id) };
window.onload = function() {
if (GBrowserIsCompatible()) {
g.map = new GMap2($("map"));
g.map.addControl(new GLargeMapControl());
g.map.addControl(new GMapTypeControl());
g.map.addControl(new GScaleControl());
g.geocoder = new GClientGeocoder();
g.getCoordinates = function(address) {
g.geocoder.getLatLng(
address,
function(point) {
if (point) {
g.map.setCenter(point, 13);
var marker = new GMarker(point);
g.map.addOverlay(marker);
var info = "<strong>" + address + "&
lt;/strong><br />坐标: 纬度=" + point.lat() + ",经度=" + point.lng();
$("info").innerHTML = info;
marker.openInfoWindowHtml(info);
marker.__address_info = info;
GEvent.addListener(marker, "click", function() {
g.map.setCenter(this.getLatLng());
this.openInfoWindowHtml(this.__address_info);
$("info").innerHTML = info;
});
}
else {
alert("无法解析: " + address);
}
}
)
}
$("btn_go").onclick = function() {
g.getCoordinates($("address").value);
}
$("btn_go").onclick();
}
else {
alert('不支持的浏览器');
}
}
window.onunload = function() {
GUnload();
}
</script>
<style media="screen">
body
{
margin: 0;
padding: 0;
font-size: 9pt;
line-height: 1.5em;
}
#frame
{
width: 700px;
margin: 20px auto 10px;
}
#form
{
margin: 0 0 10px;
text-align: center;
}
#form input
{
border: 1px solid #ccc;
font-size: 9pt;
width: 200px;
}
#form button
{
font-size: 9pt;
border: 1px solid #ccc;
}
#form button:hover
{
background: #eef;
}
#map
{
height: 400px;
margin: 0 0 10px;
border: 5px solid #ccc;
}
</style>
</head>
<body>
<div id="frame">
<div id="form">
输入一个地址:
<input id="address" value="上海市浦东新区张江镇" />
<button id="btn_go">
获取坐标</button>
</div>
<div id="map">
</div>
<div id="info">
</div>
</div>
</body>
</html>
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询