Reputation: 3674
I have two issues with Google's location detection. I am using the basic code of this example: http://code.google.com/intl/de-DE/apis/maps/documentation/javascript/examples/map-geolocation.html
1.) When a visitor declines his location to be detected, then the map will not show. That cripples the site. How can I show a fallback map with standard functionality and without location detection?
2.) Is there a way to interact with the result of the browser dialogue that asks the viewer to detect his location? If a viewer declines his location to be detected and if the above point 1.) is not possible, then it would be good to hide the map alltogether.
Upvotes: 0
Views: 509
Reputation: 1813
In the else
part of the handleNoGeolocation
function you would provide your fallback code giving a default location or another means of location detection.
Here's an alternative structure for the functions that's a little drier and uses Google's IP geolocation for fallback:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(updatePosition, ipPosition, { options... });
} else {
ipPosition();
}
function ipPosition() {
updatePosition(google.loader.ClientLocation);
}
function updatePosition(position) {
if (position == null) {
return updatePosition(defaultPlace());
}
// Firefox 3.6 passes in a non-standard position object with lat/lng at the top level instead of in .coords
var coords = (position.hasOwnProperty("coords")) ? position.coords : position;
if (coords == null) {
return updatePosition(defaultPlace());
}
[...]
}
Upvotes: 2
Reputation: 3524
In that sample there is a function handleNoGeolocation
that they use when the user don't have or declines positioning. With the same technique you should be able to handle the hiding of the map.
Upvotes: 0