Back to "Dead Simple Geolocation"

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

Imported mostlylucidcouk

Dead Simple Geolocation

Sunday, 28 February 2010

Πλάκα κάνεις με αυτά τα πράγματα τελευταία, @TheCodeJunkie Το ζήτησε έτσι εδώ είναι ένας πραγματικά απλός τρόπος για να πάρετε μια θέση και να δείξει ένα χάρτη:). W3C Geolocation API σε προγράμματα περιήγησης που το υποστηρίζουν (FireFox 3.5, Safari, iPhone, Opera) και πέφτει πίσω στη χρήση Google Gears σε άλλα προγράμματα περιήγησης (συμπεριλαμβανομένων των IE).

Απλά ένα πραγματικά ηλίθιο δείγμα αυτή τη στιγμή, αλλά ποιος ξέρει, κάποιος μπορεί να το βρει χρήσιμο! Θα ενημερώσω αργότερα με μερικά από τα πιο προηγμένα πράγματα που δουλεύω σε αυτόν τον τομέα

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
    <script src="Scripts/gears_init.js" type="text/javascript"></script>
    <script type="text/javascript">
        function SetLocation() {
            if (typeof (navigator.geolocation) != "undefined") {
                geo = navigator.geolocation;
                positionOptions = { maximumAge: 600000 };
            }
            else {
                if (!window.google || !google.gears) {
                returnUrl = this.location.href;
                location.href = "http://gears.google.com/?action=install&message=Gears now enabled!" +
                    "&return=" + returnUrl;
                }

                geo = google.gears.factory.create('beta.geolocation');
                positionOptions = {enableHighAccuracy:true, maximumAge: 600000};
            }
            geo.getCurrentPosition(GetMap, handleError,positionOptions);
        }
        function GetMap(position) {

            latitude = position.coords.latitude;
            longitude = position.coords.longitude;
            map = new VEMap('myMap');
            map.HideDashboard();

            map.LoadMap(new VELatLong(latitude, longitude), 15, 'h', false);
            var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter()); shape.SetTitle('You are here!'); map.AddShape(shape);
        }
        function handleError(positionError) {
            alert('Attempt to get location failed: ' + positionError.message);
        }      
    </script>
</head>
<body onload="SetLocation();">
    <div id='myMap' style="position: relative; width: 1000px; height: 1000px;">
    </div>
</body>
</html>
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.