Reputation: 1
I need to divide current location radius (1000 meters) area into equal parts(100 meter each part) and get those center point coordinates in google map SDK. I am using google map sdk in my app. can any one help me?
Thank you in advance.
Upvotes: 0
Views: 1596
Reputation: 17
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;
Upvotes: 1
Reputation: 234
try this
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
}
Generate Random Coordinates Function
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)
}
}
Upvotes: 0