最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Google Maps API in Javascript, Draw the radius of a circle? - Stack Overflow

programmeradmin0浏览0评论

I am looking for a way to draw the radius of the circle or a line from the center of the circle to the edge of the circle (at a precise coordinate in degrees).

Is it possible? How?

Currently, I drew a circle with the API from the center of my map. I do not think it helps ...

Example of what I would :

var sunCircle = {
          strokeColor: "#c3fc49",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#c3fc49",
          fillOpacity: 0.35,
          map: map,
          center: latlng,
          radius: 1500
        };
        cityCircle = new google.maps.Circle(sunCircle)

I am looking for a way to draw the radius of the circle or a line from the center of the circle to the edge of the circle (at a precise coordinate in degrees).

Is it possible? How?

Currently, I drew a circle with the API from the center of my map. I do not think it helps ...

Example of what I would : http://twitpic.com/aq40vv

var sunCircle = {
          strokeColor: "#c3fc49",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#c3fc49",
          fillOpacity: 0.35,
          map: map,
          center: latlng,
          radius: 1500
        };
        cityCircle = new google.maps.Circle(sunCircle)
Share Improve this question edited Dec 9, 2013 at 4:08 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Sep 1, 2012 at 21:53 user1603136user1603136 1
  • You should post the code that you have tried so far. – The Alpha Commented Sep 1, 2012 at 22:56
Add a comment  | 

3 Answers 3

Reset to default 10

Try this (Not sure if this is what you asked for)

HTML:

<div id="map_canvas"></div>​

JS:

var map;
var latlng = new google.maps.LatLng(-34.397, 150.644);
function initialize() {
    var mapOptions = {
        center: latlng,
        zoom: 9,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var el=document.getElementById("map_canvas");
    map = new google.maps.Map(el, mapOptions);

    var marker = new google.maps.Marker({
        map: map,
        position: latlng
    });

    var sunCircle = {
        strokeColor: "#c3fc49",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: "#c3fc49",
        fillOpacity: 0.35,
        map: map,
        center: latlng,
        radius: 15000 // in meters
    };
    cityCircle = new google.maps.Circle(sunCircle)
    cityCircle.bindTo('center', marker, 'position');
}
initialize();

DEMO.

Reference : Here and also this could be useful.

The perfect thing for this is the computeOffset(from:LatLng, distance:number, heading:number, radius?:number) function from the google.maps.geometry.spherical namespace, as referenced in the documentation

From there on just create a polyline from the center of the circle with the radius of itself as the offset, you can check a quick example I made here (just click around the map to see it working)

I agree with @The Alpha

        // The marker
        var marker = new google.maps.Marker({
            position: startLatLng,
            map: map,
            icon: './img/marker.png'
        });

        var circle = {
            center: startLatLng,
            map: map,
            strokeColor: "#F26836",
            strokeOpacity: 0.2,
            strokeWeight: 2,
            fillColor: "#322F6A",
            fillOpacity: 0.2,
            radius: 50 // in meters
        };

        mapCircle = new google.maps.Circle(circle)
        mapCircle.bindTo('center', marker, 'position');
发布评论

评论列表(0)

  1. 暂无评论