2011-07-12 48 views

回答

21

應該可以的。根據此article,HTML5位置對象以米爲單位返回精度屬性。

谷歌地圖api有能力繪製以圓心爲中心點(lat,lng)和以米爲單位的半徑。

我想是這樣的:

var latitude = position.coords.latitude; 
var longitude = position.coords.longitude; 
var accuracy = position.coords.accuracy; 

var centerPosition = new google.maps.LatLng(latitude, longitude); 

var marker = new google.maps.Marker({ 
    position: centerPosition, 
    map: //your map, 
    icon: //the dot icon 
}); 

var circle = new google.maps.Circle({ 
    center: centerPosition, 
    radius: accuracy, 
    map: //your map, 
    fillColor: //color, 
    fillOpacity: //opacity from 0.0 to 1.0, 
    strokeColor: //stroke color, 
    strokeOpacity: //opacity from 0.0 to 1.0 
}); 

//set the zoom level to the circle's size 
map.fitBounds(circle.getBounds()); 
+0

我必須失去更多的東西。我已經在這裏與你的例子,看看我是否可以把它釘住更多http://jsfiddle.net/mgifford/PhzsR/35/ 任何想法,將不勝感激。 –

+1

哎呀!,看起來像我的代碼示例中有一些拼寫錯誤。我會更新它。這裏是更新的小提琴:http://jsfiddle.net/PhzsR/62/ –

+0

@BryanWeaver即使關閉了HTTPS Everywhere,並且在jsfiddle中使用非HTTPS請求,似乎無法使小提琴工作 - 仍然存在錯誤在控制檯:(*定位你...許可證拒絕錯誤,同時找到你的位置* –

0
 
    var circle; 

    function initialize() { 
     // Create the map. 
     var mapOptions = { 
      zoom: 4, 
      center: new google.maps.LatLng(37.09024, -95.712891), 
      mapTypeId: google.maps.MapTypeId.TERRAIN 
     }; 

     var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 

     // Construct the circle for each value in citymap. 
     // Note: We scale the area of the circle based on the population. 
     var populationOptions = { 
      strokeColor: '#FF0000', 
      strokeOpacity: 0.8, 
      strokeWeight: 2, 
      fillColor: '#FF0000', 
      fillOpacity: 0.35, 
      map: map, 
      center: citymap[city].center, 
      radius: Math.sqrt(citymap[city].population) * 100 
     }; 
     // Add the circle for this city to the map. 
     circle = new google.maps.Circle(populationOptions); 
    } 

來源:Google documentation