0

필자는지도를 클릭하고 방금 클릭 한 핀의 위도와 경도를 가져야하지만이 애플리케이션을 사용하지 않는 경우이 애플리케이션을 사용합니다. 어쨌든, heres는 내 코드 탭을 인식 : 내가 디버그를 수행하고 내가 거기에 정지 나던 방법 onMapClick에 중단 점을 넣을 때, 어쨌든} 을안드로이드 - Google지도 V2가 퓨즈 위치와 함께 작동하지 않습니다.

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, 
     GoogleMap.OnMapClickListener, 
     View.OnClickListener, 
     GoogleApiClient.ConnectionCallbacks, 
     GoogleApiClient.OnConnectionFailedListener { 

GoogleMap mMap; 
Double latitud, longitud; 
Marker marker; 
Button buttonAgregarUbicacion; 
protected GoogleApiClient mGoogleApiClient; 
protected Location mLastLocation; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 


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

    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 
    checkGpsEnable(locationManager); 
    buildGoogleApiClient(); 



    buttonAgregarUbicacion = (Button) findViewById(R.id.button_agregar_ubicacion); 

    buttonAgregarUbicacion.setOnClickListener(this); 


} 

protected synchronized void buildGoogleApiClient() { 
    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(LocationServices.API) 
      .build(); 
} 




private void checkGpsEnable(LocationManager locationManager) { 
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && 
      !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
     alertDialogBuilder.setMessage("Al parecer no tienes el GPS activado, para mejorar la experiencia enciéndolo.") 
       .setCancelable(false) 
       .setPositiveButton("Activar GPS", 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           Intent callGPSSettingIntent = new Intent(
             Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
           startActivity(callGPSSettingIntent); 
          } 
         }); 
     alertDialogBuilder.setNegativeButton("Cancelar", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         dialog.cancel(); 
         finish(); 
        } 
       }); 
     AlertDialog alert = alertDialogBuilder.create(); 
     alert.show(); 
    } 
} 



@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 
    mMap.getUiSettings().setMyLocationButtonEnabled(true); 
    mMap.setMyLocationEnabled(true); 

    if (mLastLocation != null) { 
     mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
       new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()), 200)); 

     CameraPosition cameraPosition = new CameraPosition.Builder() 
       .target(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude())) 
       .zoom(17) 
       .build(); 
     mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

    } 


} 



@Override 
public void onClick(View view) { 
    switch (view.getId()) { 
     case R.id.button_agregar_ubicacion: 

      if (latitud == null) { 
       Toast.makeText(MapsActivity.this, "Pon un pin en el mapa", Toast.LENGTH_SHORT).show(); 
      } else { 

       Intent intent = new Intent(this, CreateReportActivity.class); 
       intent.putExtra("latitud", latitud); 
       intent.putExtra("longitud", longitud); 
       startActivity(intent); 
       finish(); 

      } 

      break; 
    } 
} 


@Override 
public void onConnected(Bundle connectionHint) { 
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 
    onMapReady(mMap); 

} 

@Override 
public void onConnectionSuspended(int i) { 
    mGoogleApiClient.connect(); 
} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 

} 

@Override 
protected void onStart() { 
    super.onStart(); 
    mGoogleApiClient.connect(); 
} 

@Override 
protected void onStop() { 
    super.onStop(); 
    if (mGoogleApiClient.isConnected()) { 
     mGoogleApiClient.disconnect(); 
    } 
} 

@Override 
public void onMapClick(LatLng latLng) { 
    mMap.clear(); 
    marker = mMap.addMarker(new MarkerOptions() 
      .position(latLng).title("¿Aquí?")); 
    mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 
    latitud = latLng.latitude; 
    longitud = latLng.longitude; 
} 

을, 나는 이것을 사용했다하지만 난 융합 위치를 구현 didnt한다있다 오늘까지 나는이 문제를 겪고있다.

정말 감사하게 생각하고 있습니다. 누군가 도와 주시면 감사하겠습니다.

감사합니다.

답변

1

지도의 경우 GoogleMap.OnMapClickListener을 잊어 버렸습니다.

당신의 onMapReady이 추가 :

mMap.setOnMapClickListener(this); 
+0

내가 지금 정말 바보가 된 기분, 대단히 @antonio 감사합니다 – miguelacio

관련 문제