I have a javascript which can draw a circle around a marker icon where the Marker icon is the location of a typed address. I have latitudes and longitudes of few thousands of points in excel file. I want to show these points on the google map but within the circl开发者_StackOverflow社区e only. Any solution in javascript will be much appreciated.
Thanks, Monir
Get your points into a more web friendly format. JSON is great. Then you can load them directly into your page. From there, you can calculate the distance between any point and your marker using the following:
function distance(lat1, lng1, lat2, lng2) {
var radius = 3956.0; // miles
var deltaLat = ToRadians(lat2 - lat1);
var deltaLng = ToRadians(lng2 - lng1);
var sinLat = Math.sin(0.5*deltaLat);
var sinLng = Math.sin(0.5*deltaLng);
var cosLat1 = Math.cos(ToRadians(lat1));
var cosLat2 = Math.cos(ToRadians(lat2));
var h1 = sinLat*sinLat + cosLat1*cosLat2*sinLng*sinLng;
var h2 = Math.sqrt(h1);
var h3 = 2*Math.asin(Math.min(1, h2));
var distance = radius*h3;
return distance;
}
function ToRadians(degree) {
return (degree * (Math.PI / 180));
}
If the distance is less than your radius, then you show it.
Bob
精彩评论