我想显示我的点 NSArray *chSpot = [parser parseArray:responseObject];
接收 3 个对象,我想显示每个位置的经纬度
并根据我的位置找到最近的地点...我正在使用此代码:
NSArray *chSpot = [parser parseArray:responseObject];
//GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[locLat doubleValue]
//经度:[locLong doubleValue]
//缩放:4];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:nil];
mapView_.myLocationEnabled = YES;
mapView_.settings.myLocationButton = YES;
for (int i=0; i<chSpot.count; i++)
{
ChargingSpots *spot = [chSpot objectAtIndex:i];
NSString *locLat = spot.LocationLat;
NSString *locLong = spot.LocationLong;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake([locLat doubleValue], [locLong doubleValue]);
marker.title = @"Amman";
marker.snippet = @"Jordan";
mapView_.delegate=self;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.icon = [UIImage imageNamed"car"];
marker.map = mapView_;
}
//[mapView_ setSelectedMarker:marker];
self.view = mapView_;
//
//
//CLLocation *locationA = [[CLLocation alloc] initWithLatitude:[locLat doubleValue] longitude:[locLong doubleValue]];
//
//CLLocation *locationB = [[CLLocation alloc] initWithLatitude:[locLat doubleValue] longitude:[locLong doubleValue]];
//
//CLLocationDistance distance = [ locationA distanceFromLocation:locationB];
//
//NSLog (@"%f",distance);
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[self.locationManager startUpdatingLocation];
Best Answer-推荐答案 strong>
在 locationManager 的委托(delegate)方法 locationManager:didUpdateLocations: 中,您可以获得当前位置,它提供了计算 distanceFromLocationconst CLLocation *)location 的方法
CLLocationDistance distA = [currentLocation distanceFromLocation: locationA];
CLLocationDistance distB = [currentLocation distanceFromLocation: locationB];//等等
关于ios - 显示位置并在 ios 中找到最近的位置,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/32477399/
|