如何向 rich:gmap 组件添加标记?
我可以看到我无法在属性中指定 gmap 标记。我想我需要在这个标签内使用 a4j 函数。问题是我对这个东西完全是新手......有人能告诉我该怎么做吗?一步一步的解决方案将不胜感激...我有API密钥和地图组件(与经纬度、缩放等一起使用),但需要在地图中心留下一个标记...
<rich:gmap gmapVar="map" id="map" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"
我相信有一个简单的方法这样做的方法...
更新:
<a4j:form>
<rich:gmap gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.658471" lng="12.59084" mapType="G_NORMAL_MAP" zoom="12">
</rich:gmap>
<script type="text/javascript">
window.onload = function() {
mapVar.addOverlay(new GMarker(50, 12));
}
</script>
</a4j:form>
这并不快乐,我尝试以编程方式完成所有事情,但仍然没有快乐。它显示标记,但每次(无论我的坐标是什么)它都显示在左上角。这是程序代码:
<head>
<title>map</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
map.addOverlay(new GMarker(38, -130));
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
请帮忙。
更新2: map.jsp 文件的主体:
<f:view>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a4j:form>
<rich:gmap id="mapVar" gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.664515" lng="12.579517" mapType="G_NORMAL_MAP" zoom="12">
</rich:gmap>
<script type="text/javascript">
window.onload = function() {
mapVar.addOverlay(new GMarker(new GLatLng(55.658471, 12.59084)));
}
</script>
</a4j:form>
</body>
</html>
</f:view>
I can see that I cannot specify the gmap marker in atribute.. I suppose that I need to use a4j function inside this tag. The problem is that I am complete newbie to this stuff... Could anyone tell me how to do this? step by step solution would be greatly appreciated... I have api key and map component (worked with lat and lng, zoom, etc) but need to leave a marker in the center of the map...
<rich:gmap gmapVar="map" id="map" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"
I believe there is an easy way to do that...
UPDATE:
<a4j:form>
<rich:gmap gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.658471" lng="12.59084" mapType="G_NORMAL_MAP" zoom="12">
</rich:gmap>
<script type="text/javascript">
window.onload = function() {
mapVar.addOverlay(new GMarker(50, 12));
}
</script>
</a4j:form>
This one is no joy, I tried to do everything programaticaly, but still no joy. It displays the marker, but every time (no matter what are my coordinates) it is displayed in top left corner. Here is the programatic code:
<head>
<title>map</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
map.addOverlay(new GMarker(38, -130));
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
Please help.
UPDATE 2:
The body of map.jsp file:
<f:view>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a4j:form>
<rich:gmap id="mapVar" gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.664515" lng="12.579517" mapType="G_NORMAL_MAP" zoom="12">
</rich:gmap>
<script type="text/javascript">
window.onload = function() {
mapVar.addOverlay(new GMarker(new GLatLng(55.658471, 12.59084)));
}
</script>
</a4j:form>
</body>
</html>
</f:view>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如:
然后(在 javascript 块中,的定义下方)
您应该查看 Google 地图 API 用于加载地图的所有可能方式。
For example:
and then (in a javascript block, below the definition of
<rich:gmap>
)You should take a look at the Google maps API for all possible ways of loading your map.