2016-08-27 2 views
0

안녕하세요 저는 초보자이며 Ios App 개발을 배우며 IDE (맞춤 위치)를 사용하여 프로그래밍 방식으로 사용자 위치를 설정하는 방법을 알고 싶습니다. -사용자 지정 사용자 위치를 프로그래밍 방식으로 표시하는 방법

enter image description here

나는 모든 것을 설치하고 위치 시스템이 내 시뮬레이터 (가짜 위치)에서 올바르게 작동합니다. 프로그래밍 방식으로 동일한 작업을 수행하고 싶은 경우 수행해야 할 작업과 해결책을 찾지 못했지만 여기에 누락 된 코드가 있습니다. -

- (IBAction)showMyLocation:(id)sender { 

    CLLocation *currentLocation=[[CLLocation alloc]initWithLatitude:75.14254 longitude:75.14254]; 
    _map.userLocation.coordinate=currentLocation.coordinate; 
    _map.showsUserLocation=YES; 

} 

이 코드는하지만 말해 보자 작동 방법

  1. 나는 액션을 트리거 할 때 발생 없음 아무것도 시뮬레이터의 위치를 ​​설정합니다.

  2. 주어진 옵션 중 하나에 위치를 설정하면 사과가 사과의 위치를 ​​표시하고 내가 작업을 트리거 할 때 나는 단지 한 번만 보여준 위치를 다시 한 번 표시합니다 사과의

soo 나를 도울 수있는 사람은 진정으로 감사 할 것이며 질문이 부적절한 모든 사람에게 사과 할 것입니다.

+0

맞춤 위치에서 한번 시도하십시오 –

+0

나는 사용자 정의 방식으로 시도합니다. 방법을 알고 싶습니다. 사용자가 작업을 트리거할지 여부를 매번 위치가 변경되도록 프로그래밍 방식으로 구현하십시오. – dreamBegin

+0

이 줄에서 더 자세히 설명 할 수 있습니다. 위치가 매번 변경 될 때마다 –

답변

2

때때로 시뮬레이터의 위치 서비스는 사용중인 API 키로 인해 영향을받습니다. 먼저 look of this link이 있어야하며 iOS에서 Google지도를 구현하려면 다음 단계를 따르세요.

다음 코드를 사용하여 사용자의 현재 위치를 가져옵니다.

CLLocationManager *locationManager; 
locationManager = [[CLLocationManager alloc] init]; 
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
[locationManager requestWhenInUseAuthorization]; 

경도 & 경도를 저장하십시오.

float latitude = locationManager.location.coordinate.latitude; 
float longitude = locationManager.location.coordinate.longitude; 

지금 당신은 프로그래밍 방식으로이 방법을

- (IBAction)showMyLocation:(id)sender { 
    CLLocationCoordinate2D centre; 
    centre.latitude = latitude; // getting latitude 
    centre.longitude = longitude; // getting longitude 

    // IF USING MkMapView 
    MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(centre, 200, 200)]; 
    [self.mapView setRegion:adjustedRegion animated:YES]; 

    // IF USING GMSMapView 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude 
                 longitude:longitude 
                  zoom:15]; 
    [self.mapView animateToCameraPosition:camera]; 
} 

를 사용하여 사용자의 위치를 ​​탐색 할 수 있습니다 : 전에 아래 이미지 참조 프로젝트의의 Info.plist 파일에 이러한 견인 키를 NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription를 추가합니다.

enter image description here

+0

내가 곧 답장을 보내 드리도록하겠습니다. 시간 내 주셔서 감사합니다. 지금은 다른 답변이 없으므로 바로 표시해 드리겠습니다.) – dreamBegin

+0

@dreamBegin 환영합니다 :) 먼저 신중하게 다른 문제를 해결할 필요가 없습니다. 감사합니다. – vaibhav

+0

동생이 나를 위해 작동하지 않는 이유 디버거의 위치에서 무엇을 선택해야합니까? – dreamBegin

1

자동으로 위치를 시뮬레이터를 열고 설정하려면이 AppleScript를 사용할 수 있습니다

tell application "Simulator" 
    activate 
end tell 

tell application "System Events" 
    tell process "Simulator" 
     tell menu bar 1 
      tell menu bar item "Debug" 
       tell menu "Debug" 
        tell menu item "Location" 
         click 
         tell menu "Location" 
          click menu item "Custom Location…" 
         end tell 
        end tell 
       end tell 
      end tell 
     end tell 

     tell window 1 
      set value of text field 1 to "52,625" 
      set value of text field 2 to "13,51" 
      click button "OK" 
     end tell 

    end tell 
end tell 

내가 내 javascript 코드 내부에 AppleScript를 실행하는 run-applescript을 사용했다.

runApplescript('tell application "Simulator" \nactivate\nend tell\ntell application "System Events"\ntell process "Simulator"\ntell menu bar 1\ntell menu bar item "Debug"\ntell menu "Debug"\ntell menu item "Location"\nclick\ntell menu "Location"\nclick menu item "Custom Location…"\nend tell\nend tell\nend tell\nend tell\nend tell\ntell window 1\nset value of text field 1 to "52,625"\nset value of text field 2 to "13,51"\nclick button "OK"\nend tell\nend tell\nend tell') 

PS : 터미널에 권한을 부여해야합니다.(시스템 환경 설정 -> 보안 & 개인 정보 보호 -> 개인 정보 탭 -> 왼쪽 메뉴의 접근성 선택 -> 목록에서 단말기 선택)

+0

위대한 .. 뭔가 새로운 :) – dreamBegin

관련 문제