Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, that's quite possible, but that in turn also depends on whether the client's webbrowser <a href="http://caniuse.com/geolocation" rel="nofollow">supports</a> HTML5 <a href="https://developer.mozilla.org/en-US/docs/WebAPI/Using_geolocation" rel="nofollow"><code>navigator.geolocation</code></a> and/or you're using the <a href="https://developers.google.com/loader/" rel="nofollow">Google Loader API</a> as fallback.</p> <p>You can grab a reference to the concrete GMap JavaScript object by <code>widgetVarName.getMap()</code> where <code>widgetVarName</code> is the <code>&lt;p:gmap widgetVar&gt;</code>. Then you can use the <a href="https://developers.google.com/maps/documentation/javascript/reference" rel="nofollow">GMap JavaScript API</a> methods on it the usual way such as <code>setCenter()</code>.</p> <p>Here's a kickoff example, provided that you want to check the geolocation by the HTML5 <code>navigator.geolocation</code> and use the Google Loader API as fallback.</p> <pre><code>&lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;p:gmap widgetVar="w_gmap" type="HYBRID" center="41.381542, 2.122893" zoom="15" style="width:600px;height:400px" /&gt; &lt;script type="text/javascript"&gt; if (navigator.geolocation) { checkGeolocationByHTML5(); } else { checkGeolocationByLoaderAPI(); // HTML5 not supported! Fall back to Loader API. } function checkGeolocationByHTML5() { navigator.geolocation.getCurrentPosition(function(position) { setMapCenter(position.coords.latitude, position.coords.longitude); }, function() { checkGeolocationByLoaderAPI(); // Error! Fall back to Loader API. }); } function checkGeolocationByLoaderAPI() { if (google.loader.ClientLocation) { setMapCenter(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude); } else { // Unsupported! Show error/warning? } } function setMapCenter(latitude, longitude) { w_gmap.getMap().setCenter(new google.maps.LatLng(latitude, longitude)); } &lt;/script&gt; </code></pre> <p>Note: the initial center location of <code>41.381542, 2.122893</code> is copypasted from <a href="http://www.primefaces.org/showcase/ui/gmapBasic.jsf" rel="nofollow">PrimeFaces showcase</a> which I think represents the football stadium of their favourite club :) You're free to change it to anything else, e.g. the location of your own company.</p> <p>Also note that the average webbrowser will for security reasons ask the enduser for confirmation to share the location. See also <a href="https://support.google.com/chrome/answer/142065?hl=en" rel="nofollow">Google Chrome documentation</a> and <a href="http://www.mozilla.org/en-US/firefox/geolocation/" rel="nofollow">Mozilla Firefox documentation</a> on the subject. You <strong>cannot</strong> turn off this part. The enduser has really to explicitly accept the request. If the enduser disallows it, it'll stick at the initial center location.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload