google maps geolocation #1

using google gears geolocation as fallback

by Alex Azuero

HTML

<div id='map'></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>

CSS

#map {
    width: 400px;
    height: 400px;
}

JavaScript

$().ready(function() {
    var initialLocation;
    var contentHtml = '<div>Ешь кокосы, жуй бананы</div>';
    var infoWindow = new google.maps.InfoWindow({
        content: contentHtml
    });
    var locationMarker = new google.maps.Marker({
        title: 'Сюда нанести ядерный удар'        
    });
    var siberia = new google.maps.LatLng(60, 105);
    var newyork = new google.maps.LatLng(40.6984, -73.9514);
    var w3cSupported = false;
    
    var mapOptions = {
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP       
    };

    var map = new google.maps.Map(
        $('#map')[0],
        mapOptions
    );
    locationMarker.setMap(map);
    
    google.maps.event.addListener(locationMarker, 'click', function() {
        infoWindow.open(map, locationMarker);
    });
    
    if (navigator.geolocation) {
        w3cSupported = true;
        navigator.geolocation.getCurrentPosition(function(position) {
            initialLocation = new google.maps.LatLng(
                position.coords.latitude,
                position.coords.longitude
            );
            map.setCenter(initialLocation);
            locationMarker.setPosition(initialLocation);
        }, function() {
            handleNoGeolocation(w3cSupported);
        });
    } else if (google.gears) {
        w3cSupported = false;
        var geo = google.gears.factory.create('beta.geolocation');
        geo.getCurrentPosition(function(position) {
            initialLocation = new google.maps.LatLng(
                position.coords.latitude,
                position.coords.longitude
            );
            map.setCenter(initialLocation);
            locationMarker.setPosition(initialLocation);
        }, function() {
            handleNoGeolocation(w3cSupported);
        });
    } else {
        w3cSupported = false;
        handleNoGeolocation(w3cSupported);
    }

    function handleNoGeolocation(errorFlag) {
        if (errorFlag === true) {
            alert('W3C...