0
Google지도의 LocationListener
을 사용하여지도 작업을하고 있습니다. 내 응용 프로그램에서는 사용자가 이동 한 경로를 그립니다. 사용자가 이미있는 위치에있을 때 경고를 설정하려고합니다. 그러나 나에게 이런 일을하는 서비스가 있는지, 아니면 모든 것을 구현할 수있는 서비스가 있는지 나는 모른다. 나는 geolocalization의 개념을 이해하지 못한다.기기가 이미 Google지도로 위치를 통과했는지 확인하는 방법은 무엇인가요?
그래서 나는 추적 된 경로를 지나갈 때 사용자에게 경고를 원합니다.
private class FollowMeLocationSource implements LocationSource, LocationListener {
private OnLocationChangedListener onLocationChangedListener;
private LocationManager locationManager;
private LocationListener locationListener;
private final Criteria criteria = new Criteria();
private String bestAvailableProvider;
/* Updates are restricted to one every 10 seconds, and only when
* movement of more than 10 meters has been detected.*/
private final long minTime = 2000;
private final float minDistance = 5;
private FollowMeLocationSource() {
locationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
getBestAvailableProvider();
// Specify Location Provider criteria
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
locationManager.requestLocationUpdates(bestAvailableProvider,minTime,minDistance,this);
}
private void getBestAvailableProvider() {
/* The preffered way of specifying the location provider (e.g. GPS, NETWORK) to use
* is to ask the Location Manager for the one that best satisfies our criteria.
* By passing the 'true' boolean we ask for the best available (enabled) provider. */
bestAvailableProvider = locationManager.getBestProvider(criteria, true);
Log.i(TAG,"bestAvailableProvider: " + bestAvailableProvider);
}
/* Activates this provider. This provider will notify the supplied listener
* periodically, until you call deactivate().
* This method is automatically invoked by enabling my-location layer. */
@Override
public void activate(OnLocationChangedListener listener) {
Log.i(TAG,"activate");
// We need to keep a reference to my-location layer's listener so we can push forward
// location updates to it when we receive them from Location Manager.
onLocationChangedListener = listener;
// Request location updates from Location Manager
if (bestAvailableProvider != null) {
//locationManager.requestLocationUpdates(bestAvailableProvider, minTime, minDistance, this);
Log.i(TAG,"activate, bestProvider != null");
locationManager.requestLocationUpdates(bestAvailableProvider,minTime,minDistance,this);
} else {
Log.i(TAG,"activate, bestProvider == null");
// (Display a message/dialog) No Location Providers currently available.
}
}
/* Deactivates this provider.
* This method is automatically invoked by disabling my-location layer. */
@Override
public void deactivate() {
Log.i(TAG,"deactivate");
// Remove location updates from Location Manager
locationManager.removeUpdates(this);
onLocationChangedListener = null;
}
@Override
public void onLocationChanged(Location location) {
Log.i(TAG,"onLocationChanged. Latitude: " + location.getLatitude() + " - Longitude: " + location.getLongitude());
/* Push location updates to the registered listener..
* (this ensures that my-location layer will set the blue dot at the new/received location) */
if (onLocationChangedListener != null) {
onLocationChangedListener.onLocationChanged(location);
}
/* ..and Animate camera to center on that location !
* (the reason for we created this custom Location Source !) */
listaRota.add(location);
if (listaRota.size() == 1) {
mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(),location.getLongitude())).title("Inicio"));
}
if (listaRota.size() >= 2) {
drawPolyLineOnMap();
}
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()),15));
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
Log.i(TAG,"onStatusChanged: " + s + ", Estado: " + i);
}
@Override
public void onProviderEnabled(String s) {
Log.i(TAG,"onProviderEnabled: " + s);
}
@Override
public void onProviderDisabled(String s) {
Log.i(TAG,"onProviderDisabled: " + s);
}
}
public void drawPolyLineOnMap() {
List<LatLng> list = new ArrayList<>();
for(Location l : listaRota) {
list.add(new LatLng(l.getLatitude(),l.getLongitude()));
}
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.BLUE);
polylineOptions.width(15);
polylineOptions.addAll(list);
mMap.clear();
mMap.addPolyline(polylineOptions);
}
이 서비스는 100 개 영역 만 지원합니다. 이 서비스는 내 응용 프로그램에서 작동하지 않습니다. 그리고 그 지역은 원형이고 나는 직선 제한이 필요합니다. – Augusto
@Augusto 1) 100 ** 활성 ** "영역"** 장치 당 **; 2) 왜 작동하지 않았습니까? 3) 어쨌든 대상 영역 주위에 원을 만들 수 있습니다. 그런 다음이 원형 지오 펜스에 대해 경고가 표시되면 대상 영역에도 있는지 확인합니다. 하지만 가능한 해결책은 하나도 없습니다. 사용자가 설명한 것처럼 항상 맞춤 서비스를 만들 수 있습니다. –
내 문제는 운전자에게 이미 길가를 지나쳤 음을 알리는 것이므로 서클이 내 문제를 해결하지 못합니다. 따라서 폴리 라인을 추적하고 있으며 PolyUtil 메서드로 검사하고 문제의 점이 이전 점으로 생성 된 폴리 라인 안에 있는지 확인합니다. 물론 미터의 허용차가 있습니다. 이 방법이 가장 실현 가능성이 높았고 구현할 수있었습니다. 나는이 분야에 익숙하지 않았고 구현할 수 없었던 당신의 솔루션입니다. – Augusto