gpt4 book ai didi

ios - 在 ios 中显示位置并找到最近的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:42 24 4
gpt4 key购买 nike

我想显示我的点 NSArray *chSpot = [parser parseArray:responseObject];它接收 3 个对象,我想显示与其纬度和经度有关的每个位置 enter image description here

并根据我的位置找到最近的地点...我正在使用此代码:

         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];

最佳答案

在您的 locationManager 的委托(delegate)方法 locationManager:didUpdateLocations: 中,您可以获得您的当前位置,它提供了计算 distanceFromLocation:(const CLLocation *)location 的方法

CLLocationDistance distA = [currentLocation distanceFromLocation: locationA];CLLocationDistance distB = [currentLocation distanceFromLocation: locationB];//等等

关于ios - 在 ios 中显示位置并找到最近的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32477399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com