我需要将当前位置半径(1000米)区域划分为相等的部分(每个部分100米),并在谷歌地图SDK中获取这些中心点坐标。我在我的应用程序中使用谷歌地图sdk。任何人都可以帮助我吗?
提前谢谢。
答案 0 :(得分:1)
GMSCircle *circ = [GMSCircle circleWithPosition:CLLocationCoordinate2DMake(latitudeCir, longitudeCir)
radius:radiusValue];
UIColor *colr = [UIColor colorWithRed:284.0/255.0 green:51.0/255.0 blue:84.0/255.0 alpha:0.3];
circ.fillColor = colr;
circ.strokeColor = colr;
circ.map = _mapkitView;
答案 1 :(得分:0)
试试这个
var num = 0
//First we declare While to repeat adding Annotation
while num != 15 {
num += 1
let rotateDegree : CLLocationDegrees = 90
//Add Annotation
let annotation = GMSMarker()
annotation.position = generateRandomCoordinates(min: 1000, max: 10000) //this will be the maximum and minimum distance of the annotation from the current Location (Meters)
annotation.groundAnchor = CGPoint(x: 0.5, y: 0.5)
annotation.rotation = rotateDegree
annotation.icon = UIImage.init(named: "icon_machine_location")
annotation.map = mapView
}
生成随机坐标功能
func generateRandomCoordinates(min: UInt32, max: UInt32)-> CLLocationCoordinate2D {
//Get the Current Location's longitude and latitude
let currentLong = currentLocation.coordinate.longitude
let currentLat = currentLocation.coordinate.latitude
//1 KiloMeter = 0.00900900900901° So, 1 Meter = 0.00900900900901 / 1000
let meterCord = 0.00900900900901 / 1000
//Generate random Meters between the maximum and minimum Meters
let randomMeters = UInt(arc4random_uniform(max) + min)
//then Generating Random numbers for different Methods
let randomPM = arc4random_uniform(6)
//Then we convert the distance in meters to coordinates by Multiplying number of meters with 1 Meter Coordinate
let metersCordN = meterCord * Double(randomMeters)
//here we generate the last Coordinates
if randomPM == 0 {
return CLLocationCoordinate2D(latitude: currentLat + metersCordN, longitude: currentLong + metersCordN)
}else if randomPM == 1 {
return CLLocationCoordinate2D(latitude: currentLat - metersCordN, longitude: currentLong - metersCordN)
}else if randomPM == 2 {
return CLLocationCoordinate2D(latitude: currentLat + metersCordN, longitude: currentLong - metersCordN)
}else if randomPM == 3 {
return CLLocationCoordinate2D(latitude: currentLat - metersCordN, longitude: currentLong + metersCordN)
}else if randomPM == 4 {
return CLLocationCoordinate2D(latitude: currentLat, longitude: currentLong - metersCordN)
}else {
return CLLocationCoordinate2D(latitude: currentLat - metersCordN, longitude: currentLong)
}
}