0

Google지도 API를 더 잘 이해하기 위해 Android 앱을 개발하고 있습니다. 이 앱에서는 마커를 보여주고 싶습니다. 안드로이드가 사용자의 현재 위치를 알고 있다면지도에 표시하려고합니다. Google 튜토리얼에 따라 작업을 수행합니다. 하지만지도를 가져 와서 Google Api 클라이언트 연결을 만드는 더 좋은 방법은 의심 스럽습니다. 튜토리얼 https://developers.google.com/maps/documentation/android-api/current-places-tutorial에서 개발자는 Google Api 클라이언트가 성공적으로 연결되었을 때만지도를 작성합니다. 제 연구에서 이런 식으로하는 것이 맞습니까? 필자의 경우 중요한 것은지도에 표시 자 위치를 표시하는 것인데, 현재 사용자 위치를 표시 할 수도 있습니다. 내 생각에 나는 반대의 방식으로했을 것이다. 빌드 맵과 맵에서만 준비 콜백은 GoogleApiClient 연결을 만든다. (필자는 API 클라이언트 연결이 현재 위치의 위치 권리를 얻기 위해에만 필요합니다 생각?)가 이런 방식으로 수행 튜토리얼에서는GoogleApiClient가 성공적으로 연결되었을 때만지도를 만드시겠습니까?

:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     ..... 
     buildGoogleApiClient(); 
     mGoogleApiClient.connect(); 
     .... 
    } 
    /** 
    * Builds a GoogleApiClient. 
    * Uses the addApi() method to request the Google Places API and the Fused Location Provider. 
    */ 
    private synchronized void buildGoogleApiClient() { 
     mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .enableAutoManage(this /* FragmentActivity */, 
         this /* OnConnectionFailedListener */) 
       .addConnectionCallbacks(this) 
       .addApi(LocationServices.API) 
       .addApi(Places.GEO_DATA_API) 
       .addApi(Places.PLACE_DETECTION_API) 
       .build(); 
     createLocationRequest(); 
    } 

@Override 
    public void onConnected(Bundle connectionHint) { 
     getDeviceLocation(); 
     // Build the map. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    */ 
    @Override 
    public void onMapReady(GoogleMap map) { 
     .... do stuff....} 

나는 다음과 같은 방법으로했을 :

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     ..... 
     buildGoogleApiClient(); 

     // Build the map. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 

    } 
    /** 
    * Builds a GoogleApiClient. 
    * Uses the addApi() method to request the Google Places API and the Fused Location Provider. 
    */ 
    private synchronized void buildGoogleApiClient() { 
     mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .enableAutoManage(this /* FragmentActivity */, 
         this /* OnConnectionFailedListener */) 
       .addConnectionCallbacks(this) 
       .addApi(LocationServices.API) 
       .addApi(Places.GEO_DATA_API) 
       .addApi(Places.PLACE_DETECTION_API) 
       .build(); 
     createLocationRequest(); 
    } 

@Override 
    public void onConnected(Bundle connectionHint) { 
     getDeviceLocation(); 

    } 

    */ 
    @Override 
    public void onMapReady(GoogleMap map) { 
     mGoogleApiClient.connect(); 
     ----do stuff.... 
    } 

답변

1

Google Play 서비스 연결이 사용 설정된 경우지도가 기기에로드되며지도가로드되지 않은 경우 마커를 플롯 할 수 없습니다.지도가로드되지 않은 경우 마커를 플롯 할 수 없습니다. 구글 플레이 서비스.

+0

왜이 튜토리얼에서 https://developers.google.com/maps/documentation/android-api/map-with-marker 개발자는지도 빌드를 보여 주며 withoud는 google play 서비스 연결을 만듭니다 (mGoogleApiClient.connect();에 대한 호출 유도)? – aeroxr1

+1

죄송합니다. 궁금한 점이 있으시면 ... – raasesh

+0

이 자습서에서는 developers.google.com/maps/documentation/android-api/... 개발자가지도를 표시하고 마커를 추가하면 google api 클라이언트 연결이됩니다. mGoogleApiClient.connect();에 대한 호출을 시작합니다. appi 클라이언트 연결은 위치를 얻는 것일 뿐인가? 아니면 내가 잘못 생각한 것일까? 그러나 첫 번째 게시물에서 질문을 편집했습니다. 아마도 더 명확 할 것입니다. – aeroxr1