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
3 Answers
Reset to default 10Try 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');