谷歌地图API问题

小p变砖头 2010-07-28 10:08:33
大家好!我最近研究Google Maps API。想创建一个这样的应用:1>地图开始自动定位一经纬度并显示标签 2>当用户单击标签时显示掉话两个字。(移动前后都可实现)3>当用户移动地图时在地图下方显示移动后地图的经纬度。遇到问题:点击标签时并不显示信息,而是移动map并触发moveMap函数。请问该问题应如何解决,谢谢!(还有一个问题,如何获得当前鼠标指向的或点击的位置的经纬度,而不是地图中心的?)
附上源代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>myMap with Google Maps API</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script src="http://maps.google.com/maps?file=api&v=1&key=XXXXXX" type="text/javascript"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<div id="map" style="width: 500px; height:400px"></div>
<script type="text/javascript">
//<!CDATA[
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(116.46036,39.83358),4);
var marker = new GMarker(new GPoint(116.46036,39.83358));
map.addOverlay(marker);
GEvent.addListener(map,"move",moveMap);
GEvent.addListener(marker,"click",showInfo);

function showInfo()
{
marker.openInfoWindowHtml('<b>掉话</b>');
}

function moveMap()
{
var point = map.getCenterLatLng();
if(marker)
map.removeOverlay(marker);
document.getElementById("jingdu").innerText=point.x;
document.getElementById("weidu").innerText=point.y;
marker = new GMarker(new GPoint(point.x,point.y));
map.addOverlay(marker);
GEvent.addListener(marker,"click",showInfo);
}
//]]>
</script>
Google Map API<br>
<h3 id="jingdu"></h3><br/><h3 id="weidu"></h3>
</body>
</html>
...全文
99 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
小p变砖头 2010-07-28
  • 打赏
  • 举报
回复
没人知道吗 耐心等待

6,721

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 Google技术社区
社区管理员
  • Google技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧