2014-12-21 1 views
1

GPS없이 내 장치에 가짜 GPS 좌표를 사용해야합니다. 이 설명서를 사용하려고합니다 : http://developer.android.com/training/location/location-testing.html모의 위치를 ​​구현하는 방법은 무엇입니까?

하지만 import com.google.android.gms.location.LocationClient를 사용할 수 없습니다. 내가 아는 바대로 그것은 더 이상 사용되지 않습니다. 그러나 모의 위치를 ​​구현하는 방법은 무엇입니까?

답변

1

합니다.

  1. 초기화 GoogleApiClient :

    private GoogleApiClient mGoogleApiClient; 
    
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); 
    
  2. 클라이언트를 연결합니다

    mGoogleApiClient.connect(); 
    
  3. 설정 새로운 위치 : 우리가 내장 공사용는

    Location location = new Location(LocationManager.GPS_PROVIDER); 
    location.setLatitude(48.446743); 
    location.setLongitude(52.44672); 
    location.setAccuracy(4.0f); 
    location.setElapsedRealtimeNanos(elapsedTimeNanos); 
    location.setTime(currentTime); 
    LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, location); 
    
  4. 을 Hed, 클라이언트의 연결을 해제 데 필요한 :

    if (mGoogleApiClient.isConnected()) { 
        mGoogleApiClient.disconnect(); 
    } 
    
+0

안녕하세요,이 코드를 시도하고 그것은 작동합니다. 앱이 공개 될 때까지만 앱을 닫고 "Google지도"를 열면 내 "실제"위치가 현재 위치가됩니다. 그 문제를 해결하는 방법에 대한 아이디어가 있습니까? –

관련 문제