在研究過程中發現了許多解決方案。任何解決方案都可能適合你。
解決方法:1
int x = (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y = (int) ((MAP_HEIGHT/180.0) * (90 - lat));
解決方案:2
func addLocation(coordinate: CLLocationCoordinate2D)
{
// max MKMapPoint values
let maxY = Double(267995781)
let maxX = Double(268435456)
let mapPoint = MKMapPointForCoordinate(coordinate)
let normalizatePointX = CGFloat(mapPoint.x/maxX)
let normalizatePointY = CGFloat(mapPoint.y/maxY)
print(normalizatePointX)
print(normalizatePointX)
}
Solutuin:3
x = (total width of image in px) * (180 + latitude)/360
y = (total height of image in px) * (90 - longitude)/180
注意:使用緯度的負經度時一定要加上或減去負數字,即+( - 92)或 - ( - 35),這實際上是-92和+35