var wgs84Sphere = new ol.Sphere(6378137); ol.Sphere is not a constructor
时间: 2024-03-08 08:48:39 浏览: 113
It seems that there is an error in your code. The ol.Sphere class does not have a constructor method. Instead, you should create a new instance of the ol.Sphere class using the static method `ol.Sphere.getDistance()`.
Here's an example of how to create a new instance of the ol.Sphere class and use it to calculate the distance between two points:
```
var wgs84Sphere = new ol.Sphere(6378137);
var point1 = [0, 0]; // lon, lat in radians
var point2 = [Math.PI / 2, Math.PI / 2]; // lon, lat in radians
var distance = wgs84Sphere.getDistance(point1, point2);
console.log(distance); // output: 10018754.171394622 (meters)
```
In this example, we create a new instance of the ol.Sphere class with a radius of 6378137 meters (the radius of the WGS84 ellipsoid). Then, we define two points in radians (point1 and point2) and use the `getDistance()` method of the ol.Sphere class to calculate the distance between them. Finally, we log the distance to the console.
阅读全文