2014-02-28 3 views
1

Google지도를 사용하고 있으며 사용자가 현재 위치를 사용하여 (지도에 배치 된) 마커 반경에 있는지 감지 할 수 있기를 원합니다. . 사용자에게 현재 위치 좌표 (위도와 경도)와 마커 좌표가 있지만 사용자가 해당 지역에 있는지 여부를 계산하는 방법을 알지 못합니다. 아래 그림은 내가하고 싶은 것을 가장 잘 묘사합니다.Android Google Map 사용자가 마커 서클 영역에 있는지 확인하는 방법

map.OnInfoWindowClickListener(new OnInfoWindowClickListener()){ 
    public void isUserInArea(Marker marker){ 

     float[] distance = new float[2]; 
      //users current location 
     Location.distanceBetween(currentLocation.getLatitude(),currentLocatiocation.getLongitude(), 
     marker.getPosition().latitude, marker.getPosition().longitude, distance); 
} 

내가 마커 원의 보류를 얻을 수 없기 때문에 현재 위치가 표시 자 영역 내에있는 경우 발견하지 않습니다

enter image description here

는이 같은 알고리즘을 가지고있다. 그러나 내가 가지고있는 가장 가까운 곳이에요. 도와 주셔서 감사합니다.

Location.distanceBetween(mMarker.getPosition().latitude, 
      mMarker.getPosition().longitude, mCircle.getCenter().latitude, 
      mCircle.getCenter().longitude, distance); 

if (distance[0] > mCircle.getRadius()) { 
     //Do what you need 

}else if (distance[0] < mCircle.getRadius()) { 
//Do what you need 
} 

답변

7

같은지도에 원을 추가?

은 당신이 할 수있는 것입니다 :

map.addMarker(new MarkerOptions() 
    .title(name) 
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.gpsmap)) 
    .position(coordinates) 
    .flat(true) 
    .rotation(90)); 

을하고 다음 방법 호출 그것에 근접 경고를 추가합니다 : 대신에 원을 그리는,과 같이지도에서 Marker을 배치

// Proximity alert 
private void addProximityAlert(double lat, double lng, int id){ 
    Intent intent = new Intent(PROX_ALERT_INTENT); 
    PendingIntent proximityIntent = PendingIntent.getBroadcast(this, id, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 
    locationManager.addProximityAlert(lat, lng, POINT_RADIUS, EXPIRATION, proximityIntent); 
} 

여기에서 EXPIRATION = -1 (근접 경고가 만료되지 않음)이고 POINT_RADIUS은 이전 원의 반경 값을 사용합니다.

그런 다음 당신은지도에 근접 경고 리스너를 추가해야합니다

IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
registerReceiver(new ProximityIntentReceiver(), filter); 

PROX_ALERT_INTENT = "yourProjectPackageName.ProximityActivity";

희망이

+0

신난다는 매력처럼 일했습니다! – Khateeb321

+0

다른 사람이 답을 표시 할 수 있습니까? – Khateeb321

0

가 왜 근접 경고를 사용하지 마십시오 도움을하려면

, 나는 내가 이것을 사용이

// adding circle to map 
circleOptions = new CircleOptions(); 
circleOptions.center(new LatLng(locationlist.get(i) 
     .getLatitude(), locationlist.get(i).getLongitude())); 
circleOptions.radius(20); 
circleOptions.strokeColor(Color.BLUE); 
circleOptions.fillColor(Color.BLUE); 
map.addCircle(circleOptions); 

//check that all tasks are in circle radius 

Marker locationMarker = map.addMarker(markerOp); 
locationMarker.showInfoWindow(); 
관련 문제