为了替换谷歌地图V2的distancFrom mathod,(转换为V3)我添加了以下内容。但它给了我“谷歌没有定义”和“中心d不是一个功能”作为错误mozilla的错误控制台。任何人都可以告诉我这里做错了什么?
google.maps.LatLng.prototype.distanceFrom = function(newLatLng) {
var lat1 = this.lat();
var radianLat1 = lat1 * ( Math.PI / 180 );
var lng1 = this.lng();
var radianLng1 = lng1 * ( Math.PI / 180 );
var lat2 = newLatLng.lat();
var radianLat2 = lat2 * ( Math.PI / 180 );
var lng2 = newLatLng.lng();
var radianLng2 = lng2 * ( Math.PI / 180 );
var earth_radius = 6378100; // (km = 6378.1) OR (miles = 3959) - radius of the earth
var diffLat = ( radianLat1 - radianLat2 );
var diffLng = ( radianLng1 - radianLng2 );
var sinLat = Math.sin( diffLat / 2 );
var sinLng = Math.sin( diffLng / 2 );
var a = Math.pow(sinLat, 2.0) + Math.cos(radianLat1) * Math.cos(radianLat2) * Math.pow(sinLng, 2.0);
var distance = earth_radius * 2 * Math.asin(Math.min(1, Math.sqrt(a)));
return distance;
}
我将上述功能称为
var latConv = center.distanceFrom(new google.maps.LatLng(center.lat()+0.1, center.lng()))/100;