2012-10-03 2 views

Répondre

6

Utilisez l'approche navigator.geolocation, et utiliser une icône personnalisée pour votre cercle bleu

https://developer.mozilla.org/en-US/docs/Using_geolocation

https://developers.google.com/maps/documentation/javascript/overlays#Icons

EDIT:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Google Maps User Location</title> 
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <style> 
    html, body, #map_canvas{width:100%;height:100%;} 
    </style> 
    </head> 
    <body onload="locate()"> 
    <div id="map_canvas"></div> 
    </body> 
    <script> 
    var im = 'http://www.robotwoods.com/dev/misc/bluecircle.png'; 
    function locate(){ 
     navigator.geolocation.getCurrentPosition(initialize,fail); 
    } 

    function initialize(position) { 
     var myLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
     var mapOptions = { 
      zoom: 4, 
      center: myLatLng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     var map = new google.maps.Map(document.getElementById('map_canvas'), 
             mapOptions); 
     var userMarker = new google.maps.Marker({ 
      position: myLatLng, 
      map: map, 
      icon: im 
     }); 
     } 

    function fail(){ 
     alert('navigator.geolocation failed, may not be supported'); 
    } 
    </script> 
</html> 
+0

Comment avez-vous obtenu l'URL du cercle bleu par curiosité? –

+0

Je ne me souviens pas, peut-être juste fait dans Photoshop, n'hésitez pas à l'enregistrer à partir de cette URL, mais c'était des appareils pré-rétine. –

Questions connexes