admin管理员组文章数量:1023077
I created a circle using the Google Maps V3 API and also tried to make a circle of markers with the same radius.
Problem: The one I created is oblique while the one by Google Maps is a nice round circle. What went wrong?
Google Maps V3 Circle Code
// Draw search circle
search_circle = new google.maps.Circle;
search_circle.setCenter(target_latlng);
search_circle.setRadius(travel_time * average_speed);
search_circle.setMap(map);
I created a circle using the Google Maps V3 API and also tried to make a circle of markers with the same radius.
Problem: The one I created is oblique while the one by Google Maps is a nice round circle. What went wrong?
Google Maps V3 Circle Code
// Draw search circle
search_circle = new google.maps.Circle;
search_circle.setCenter(target_latlng);
search_circle.setRadius(travel_time * average_speed);
search_circle.setMap(map);
Share
Improve this question
edited Nov 10, 2011 at 0:49
Nyxynyx
asked Nov 9, 2011 at 12:19
NyxynyxNyxynyx
63.9k163 gold badges507 silver badges856 bronze badges
2 Answers
Reset to default 4One thing you need to remember here, the google circle is giving the distance between two points on a sphere (the earth) which is why your circle doesn't look the same.
You did not specify what the purpose of the circle in your example is, but from the code snippet I can tell it has something to do with travel distances. In that case you might be interested to look into :
The Haversine Formula
or
The Spherical Law of Cosines
Also this page could provide you with some basis on how to tweak your formula to get the correct circle shape.
Edit: For the sake of correctness, the earth is not a perfect sphere, but for all practical purposes it is assumed to be one.
To calculate distances on a sphere, you can utilize Google Maps geometry library. To request the library use:
<script type="text/javascript" src="http://maps.googleapis./maps/api/js?libraries=geometry&sensor=true_or_false"></script>
Then, your circle JS code would be:
num_theta_step = 365; // number of steps
for(theta = 0; theta < 365; theta += 365/num_theta_step) {
var circle_latlng = google.maps.geometry.spherical.puteOffset(target_latlng, R, theta);
var marker = new google.maps.Marker({
position: circle_latlng,
map: map,
title:"Hello World!"
});
}
I created a circle using the Google Maps V3 API and also tried to make a circle of markers with the same radius.
Problem: The one I created is oblique while the one by Google Maps is a nice round circle. What went wrong?
Google Maps V3 Circle Code
// Draw search circle
search_circle = new google.maps.Circle;
search_circle.setCenter(target_latlng);
search_circle.setRadius(travel_time * average_speed);
search_circle.setMap(map);
I created a circle using the Google Maps V3 API and also tried to make a circle of markers with the same radius.
Problem: The one I created is oblique while the one by Google Maps is a nice round circle. What went wrong?
Google Maps V3 Circle Code
// Draw search circle
search_circle = new google.maps.Circle;
search_circle.setCenter(target_latlng);
search_circle.setRadius(travel_time * average_speed);
search_circle.setMap(map);
Share
Improve this question
edited Nov 10, 2011 at 0:49
Nyxynyx
asked Nov 9, 2011 at 12:19
NyxynyxNyxynyx
63.9k163 gold badges507 silver badges856 bronze badges
2 Answers
Reset to default 4One thing you need to remember here, the google circle is giving the distance between two points on a sphere (the earth) which is why your circle doesn't look the same.
You did not specify what the purpose of the circle in your example is, but from the code snippet I can tell it has something to do with travel distances. In that case you might be interested to look into :
The Haversine Formula
or
The Spherical Law of Cosines
Also this page could provide you with some basis on how to tweak your formula to get the correct circle shape.
Edit: For the sake of correctness, the earth is not a perfect sphere, but for all practical purposes it is assumed to be one.
To calculate distances on a sphere, you can utilize Google Maps geometry library. To request the library use:
<script type="text/javascript" src="http://maps.googleapis./maps/api/js?libraries=geometry&sensor=true_or_false"></script>
Then, your circle JS code would be:
num_theta_step = 365; // number of steps
for(theta = 0; theta < 365; theta += 365/num_theta_step) {
var circle_latlng = google.maps.geometry.spherical.puteOffset(target_latlng, R, theta);
var marker = new google.maps.Marker({
position: circle_latlng,
map: map,
title:"Hello World!"
});
}
本文标签: javascriptGoogle Maps V3 Circle amp Circle that I created do not matchStack Overflow
版权声明:本文标题:javascript - Google Maps V3 Circle & Circle that I created do not match - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745547695a2155471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论