开发者

How to add marker to rich:gmap component?

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 compl开发者_如何转开发ete 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&amp;v=2&amp;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>


For example:

<rich:gmap var="mapVar" ... />

and then (in a javascript block, below the definition of <rich:gmap>)

window.onload = function() {
    mapVar.addOverlay(
        new GMarker(new GLatLng(#{yourBean.lat}, #{yourBean.lng})));
}

You should take a look at the Google maps API for all possible ways of loading your map.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜