8 Replies Latest reply on Mar 10, 2011 3:00 AM by v.bannur

    getting a point in rich:gmap?

    okr2004

      Hi,

      i am using a rich:gmap component like this:

      <rich:gmap lat="..." lng="..." onclick="doAnything();" gmapKey="..."/>


      How can i get the point (in the javascript-function), where the user has clicked?

      Thanks...


        • 1. Re: getting a point in rich:gmap?

          not like this. onclick on the component just gives the fact that you click on the whole object.

          To work with gmap you have to use the standard Google API. Those are most useful links.

          http://www.google.com/apis/maps/documentation/
          http://www.econym.demon.co.uk/googlemaps/


          rich:gmap has gmapVar attribute. The javascript variable that is used to access the Google Map API. If you have more than one Google Map components on the same page, use individual key for each of them. The default variable name is "map" (without quotes)

          Important: Google Map is initialize only after page is loaded. So, initiate your listeners from

          • 2. Re: getting a point in rich:gmap?
            okr2004

            Thanks for your advice.

            After registering an event listener, it works fine.

            Now i only have to find a good place to initiate the listener... :-)

            • 3. Re: getting a point in rich:gmap?

              let me know when you found it

              • 4. Re: getting a point in rich:gmap?

                If not, I can show you a couple of ways

                • 5. Re: getting a point in rich:gmap?
                  okr2004

                  I havn't found a good place yet. So you can show me some ways...

                  • 6. Re: getting a point in rich:gmap?

                    I just have added 'oninit' attribute to rich:gmap . So, the way will be much simpler. This attribute will be available since the next nightly build.

                    For previous version of richfaces, you can add one more code onload with prototype.js:

                    Event.observe(window, "load", func );

                    Ajax4jsf is shipped with Prototype.js. So, you can use it in your code. To make it available of the page, add the following code:

                    <a4j:loadScript src="resource://prototype.js" />


                    Then, you can define:
                    ....
                    function myInitFunc() {
                     // your init code for gmap
                    }
                    ....
                    Event.observe(window, "load", myInitFunc );
                    ....






                    • 7. Re: getting a point in rich:gmap?
                      okr2004

                      thanks for your help and the 'oninit'-attribute. Now it works and will try 'oninit' in the next release of richfaces.

                      • 8. Re: getting a point in rich:gmap?
                        v.bannur

                        Here is the code to get the point on click of google map

                         

                        <rich:gmap id="gm" lat="#{bean.lat}" lng="#{bean.lng}" zoom="#{bean.zoom}" gmapVar="map" locale="EN"

                          gmapKey="ABQIAAAAxU6W9QEhFLMNdc3ATIu-VxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRkrpOGzxH8_ud3inE9pG1845-FCA"

                           style="width:500px;height:400px" onclick="point(map);"/>

                         

                        <a4j:outputPanel>

                            <script>   

                            function place(map){ 

                                       alert("Lat,Lng="+map.getBounds().getNorthEast());

                                       alert("Lat="+map.getBounds().getNorthEast().lat());

                                       alert("Lng="+map.getBounds().getNorthEast().lng());

                                       var point = new  GLatLng(lat, lng);    

                           }

                        </script>

                        </a4j:outputPanel>