I'm really stuck right now at a certain point with the gmap. Maybe someone of you had the same problem or knows a solution.
First of all I was wondering how to get the initial bounds of the map. When my application starts I want to load only the markers from db which are in the map. So I do not need to load all markers stored in the db. But I can only get the bounds from onStateChange(StateChangeEvent event) in my backend and that is not fired in the beginning.
Next thing is, that I was wondering if it is possible to update the mapmodel somehow. I want to store a more complex Object to a marker including different texts and pictures. Now when adding it to the model I need to save it to the db aswell in the backend. But after storing it, how can I tell the map to update the model?
My last issue is about geolocating. When initially started I want the map to look for the users location and center itself at that point. I tried tutorials with following code. But the map simply does not react. May it be that the map is not loaded? I start my JS in the <h:body onload="geolocationLoad();"> tag. It finds my location currectly but does not alter the map. Here is my code.
JS
Code: Select all
function geolocationLoad() {
// Determine support for GeoLocation
if (navigator.geolocation) {
// Locate position
navigator.geolocation.getCurrentPosition(geolocationDisplayPosition,
geolocationErrorFunction);
} else {
alert('It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser which supports it.');
}
}
// Success callback function
function geolocationDisplayPosition(pos) {
var mylat = pos.coords.latitude;
var mylong = pos.coords.longitude;
var thediv = document.getElementById('locationinfo');
thediv.innerHTML = '<p>Your longitude is :' + mylong
+ ' and your latitide is ' + mylat + '</p>';
// Add marker
var myLocation = new google.maps.Marker({
position : pos,
map : map,
title : "You are here"
});
map.addOverlay(myLocation);
// set new center of map
map.setCenter(new GLatLng(mylat, mylong), 13);
}
// Error callback function
function geolocationErrorFunction(pos) {
alert('Error in locating!' + pos);
}
Frozone