2012-10-03 93 views

回答

6

使用navigator.geolocation方法,并使用自定义图标为您的蓝色圆圈

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

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

编辑:

<!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

出于好奇,你是如何得到蓝圈的URL的? –

+0

难以想象,可能只是在Photoshop中制作而成,随时保存该URL,但那是视网膜前装置。 –

相关问题