1

Android 앱이 있습니다. 위치 수신기로 Google지도를 사용하는 건물입니다. 지도가 처음 나타나면 위치 수신기에서 12로 확대/축소가 설정되어 있으므로 사용자가 확대/축소를 변경 한 후에 확대/축소에 영향을주지 않고 위치를 업데이트 할 수있는 방법이 궁금합니다. 아래는 내 위치 수신기입니다.사용자가 설정 한 확대/축소를 변경하지 않고지도 아이콘을 업데이트하려면 어떻게해야합니까?

/** 
*Mylocationlistener class will give the current GPS location 
*with the help of Location Listener interface 
*/ 
private class Mylocationlistener implements LocationListener { 

    @Override 
    public void onLocationChanged(Location location) { 

     if (location != null) { 
      // ---Get current location latitude, longitude--- 

      Log.d("LOCATION CHANGED", location.getLatitude() + ""); 
      Log.d("LOCATION CHANGED", location.getLongitude() + ""); 
      currentLocation = new LatLng(location.getLatitude(), location.getLongitude()); 
      currentLatLng = new LatLng(location.getLatitude(), location.getLongitude()); 
      Marker currentLocationMarker = map.addMarker(new MarkerOptions().position(currentLocation).title("Current Location")); 
      // Move the camera instantly to hamburg with a zoom of 15. 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15)); 
      // Zoom in, animating the camera. 
      map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null); 
      if (!firstPass){ 
       currentLocationMarker.remove(); 
      } 
      firstPass = false; 
      Toast.makeText(MapViewActivity.this,"Latitude = "+ 
        location.getLatitude() + "" +"Longitude = "+ location.getLongitude(), 
        Toast.LENGTH_LONG).show(); 

     } 
    } 

답변

3

로컬 변수를 수신기에 추가하고이를 사용하여 첫 번째 위치 만 확대/축소 할 수 있습니다. 코드는 다음과 같습니다.

private class Mylocationlistener implements LocationListener { 

    private boolean zoomed = false; 

    @Override 
    public void onLocationChanged(Location location) { 

    if (location != null) { 
     // ---Get current location latitude, longitude--- 

     Log.d("LOCATION CHANGED", location.getLatitude() + ""); 
     Log.d("LOCATION CHANGED", location.getLongitude() + ""); 
     currentLocation = new LatLng(location.getLatitude(), location.getLongitude()); 
     currentLatLng = new LatLng(location.getLatitude(), location.getLongitude()); 
     Marker currentLocationMarker = map.addMarker(new MarkerOptions().position(currentLocation).title("Current Location")); 
     // Move the camera instantly to hamburg with a zoom of 15. 
     map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15)); 
     // Zoom in, animating the camera. 
     if (!zoomed) { 
      map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null); 
      zoomed = true; 
     }          
     if (!firstPass){ 
      currentLocationMarker.remove(); 
     } 
     firstPass = false; 
     Toast.makeText(MapViewActivity.this,"Latitude = "+ 
       location.getLatitude() + "" +"Longitude = "+ location.getLongitude(), 
       Toast.LENGTH_LONG).show(); 

    } 
} 
+0

고마워요. 그것은 효과가 있었다. – yams