0
위치 기반 게임을 구축 중이며 사용자 위치를 올바르게 초기화하는 데 문제가 있습니다. 항상 그런 것은 아니지만 위치가 0,0에서 바뀌지 않는 경우가 있습니다.iOS Mapkit - 사용자 위치가 0, 0으로 표시됩니다.
플레이어의 위치가로드 될 때까지지도가 표시되지 않도록 차단하는 로딩보기 (볼트)가있어 문제가됩니다 (0,0). 따라서 사용자 위치가 설정되지 않으면 볼트가 열리지 않아지도가 표시됩니다.
다른 방법으로 사용자 위치를로드 할 수 있습니까? FYI - 위치 서비스가 사용 설정되어 있고 기기에 기능이 있는지 확인했습니다. 모든 것이 올바르게 활성화 된 상태에서 내 장치에서이 문제를 켜고 끕니다.
가있는 viewDidLoad :
/*Location Manager*/
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDistanceFilter:100.0];//Update location to network when player moves X meters
[locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];//Nearest 1000 meters (.33 miles)
[locationManager startUpdatingLocation];
/*Map View*/
mapLoaded = false;
currentFilter = 0;
[_mapView setDelegate:self];
[_mapView setShowsUserLocation:YES];
[_mapView setMapType:MKMapTypeSatellite];
위치 관리자 위임 :
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//Wait until User Location is initialized (NOT 0,0)
NSLog(@"Latitude: %f, Longitude: %f",_mapView.userLocation.coordinate.latitude,_mapView.userLocation.coordinate.longitude);
if(_mapView.userLocation.location.coordinate.latitude!=0.00 && _mapView.userLocation.location.coordinate.longitude!=0.00){
//Update Player Object
[player setLatitude:_mapView.userLocation.location.coordinate.latitude];
[player setLongitude:_mapView.userLocation.location.coordinate.longitude];
[player updatePlayerLocation];//Update location to network
if(mapLoaded){//Map already loaded, call refresh
[self refreshMap];
}
else{//First load of map
[_mapView setCenterCoordinate:_mapView.userLocation.location.coordinate];
[self populateMap];
[self openVault];
mapLoaded = true;//Disable map first load
//timerMap = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(refreshMap) userInfo:nil repeats:YES];//Auto-Refresh of Map
}
}
}
유레카를 참조하십시오! 따라서 문서를 검토 한 후에 캐시 된 "마지막 위치"중 일부가로드되어서 대리자 메소드가 3 ~ 4 번 호출되는 문제가있었습니다. 이전 타임 스탬프가있는 위치를 무시하는 Apple의 예를 사용하여 사용자의 현재 위치 만 가져올 수 있었고 캐시 된 위치는 무시할 수있었습니다. 내 두통 치료를 주셔서 감사합니다! – JimmyJammed
여러분을 환영합니다! 내가 도울 수있어서 기뻐. –