2016-12-21 1 views
0

마커를 추가하려면 화면을 터치하여 Google지도에 마커를 추가하십시오. Google지도가 정상적으로 작동합니다. 그러나 만지면 아무 일도 일어나지 않습니다. 다른 방법이 있습니까?Google지도에 마커를 추가하여 android를 사용하여 화면을 터치하십시오.

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    // Add a marker in Sydney and move the camera 
    LatLng sydney = new LatLng(-34, 151); 
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 

    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
    return; 
    } 
    mMap.setMyLocationEnabled(true); 
} 

답변

1

는 답을 받아이

// Setting a click event handler for the map 
    googleMap.setOnMapClickListener(new OnMapClickListener() { 

     @Override 
     public void onMapClick(LatLng latLng) { 

      // Creating a marker 
      MarkerOptions markerOptions = new MarkerOptions(); 

      // Setting the position for the marker 
      markerOptions.position(latLng); 

      // Setting the title for the marker. 
      // This will be displayed on taping the marker 
      markerOptions.title(latLng.latitude + " : " + latLng.longitude); 

      // Clears the previously touched position 
      googleMap.clear(); 

      // Animating to the touched position 
      googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 

      // Placing a marker on the touched position 
      googleMap.addMarker(markerOptions); 
     } 
    }); 
+0

감사를 사용해보십시오. 내가 도울 수있어서 기뻐.;) – itzswan

+0

할 수 있으면 대답을 또한 upvote 바랍니다. – itzswan

2

mMap 개체에 클릭 수신기를 설정합니다. OnMapClickListener. onMapClick 이벤트 내에서 코드를 삽입하여 마커를 추가합니다.

관련 문제