如何插入数组值以基于长/纬度值绘制多边形 - Google Maps iOS? [英] How to insert array values to draw polygon based on long/lat values - Google Maps iOS?
问题描述
我正在尝试GMSPolygon * polygon = [GMSPolygon polygonWithPath:rect];方法来绘制用户所点击的坐标的多边形。下面是我如何存储点击的坐标:
//数组由单击的坐标构成
NSMutableArray * latitudeTappedCoordinates = [NSMutableArray array ]。
NSMutableArray * longitudeTappedCoordinates = [NSMutableArray array];
NSUInteger numberOfLongitudeCoordinates = [longitudeTappedCoordinates count];
NSUInteger numberOfLatitudeCoordinates = [latitudeTappedCoordinates count];
for(int i = 2; i< numberOfLatitudeCoordinates; i ++){
[latitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.latitude]];
}
for(int i = 2; i< numberOfLongitudeCoordinates; i ++){
[longitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.longitude]];
}
在此之后,我有以下内容:
// polygon
GMSMutablePath * rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];
GMSPolygon * polygon = [GMSPolygon polygonWithPath:rect];
正如您所看到的,
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];
只需要一个属性。我希望它能够获取上面的数组init中的所有值,因此可以绘制多边形。我该怎么做?
首先存储float值不是数组中的int值。 $ b然后加入界面
NSMutableArray * latitudeTappedCoordinates;
NSMutableArray * longitudeTappedCoordinates;
您可以这样做:
//创建一个矩形路径
GMSMutablePath * rect = [GMSMutablePath path];
CLLocationCoordinate2D事件;
for(int i = 0; i< = [longitudeTappedCoordinates count] -1; i ++){
event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue];
event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue];
[rect addCoordinate:event];
}
GMSPolygon * polygon = [GMSPolygon polygonWithPath:rect];
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = mapView;
I am trying the GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; method to draw a polygon of the tapped coordinates by the user. Here's how I store the clicked coordinates:
// array made of clicked coordinates
NSMutableArray *latitudeTappedCoordinates = [NSMutableArray array];
NSMutableArray *longitudeTappedCoordinates = [NSMutableArray array];
NSUInteger numberOfLongitudeCoordinates = [longitudeTappedCoordinates count];
NSUInteger numberOfLatitudeCoordinates = [latitudeTappedCoordinates count];
for (int i = 2; i < numberOfLatitudeCoordinates; i++) {
[latitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.latitude]];
}
for (int i = 2; i < numberOfLongitudeCoordinates; i++) {
[longitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.longitude]];
}
After this, I have the following:
// polygon
GMSMutablePath *rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
As you can see, the line
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];
only takes in a single attribute. I want it to take in all the values in the arrays init above, so it can draw the polygon. How can I do that?
First store float values not int values in array. then
Add in interface
NSMutableArray *latitudeTappedCoordinates;
NSMutableArray *longitudeTappedCoordinates;
You can do like this :
// Create a rectangular path
GMSMutablePath *rect = [GMSMutablePath path];
CLLocationCoordinate2D event;
for (int i = 0; i <= [longitudeTappedCoordinates count]-1; i++) {
event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue];
event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue];
[rect addCoordinate:event];
}
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = mapView;
这篇关于如何插入数组值以基于长/纬度值绘制多边形 - Google Maps iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!