1
GPS 추적을 사용하는 응용 프로그램에서 작업 중입니다. Google지도에서 걷기/실행 경로를 그립니다. 내 경로를 따로 따로 저장하십시오. 내가 그것을 필요로하는 응용 프로그램에서 일하고 있어요GPS를 사용하여 걷고, 달리기, 운전하면서 Google지도에서 폴리 라인을 그리는 방법 추적 및 내 경로 저장 evrytime
public class MapActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String TAG = "MapActivity";
public GoogleMap mMap;
private ArrayList<LatLng> points;
Polyline line;
Marker now;
double lat1;
double lon1;
String provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
points = new ArrayList<LatLng>();
setContentView(R.layout.activity_map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (!mMap.isMyLocationEnabled())
mMap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = lm.getBestProvider(criteria, true);
//Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location myLocation = lm.getLastKnownLocation(provider);
if (myLocation == null) {
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = lm.getBestProvider(criteria, false);
myLocation = lm.getLastKnownLocation(provider);
}
if (myLocation != null) {
LatLng userLocation = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
lat1=myLocation.getLatitude();
lon1=myLocation.getLongitude();
mMap.addMarker(new MarkerOptions()
.position(userLocation)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
.title("Welcome")
.snippet("Latitude:"+lat1+",Longitude:"+lon1)
);
Log.v(TAG, "Lat1=" + lat1);
Log.v(TAG, "Long1=" + lon1);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 18), 1500, null);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, new LocationListener() {
@Override
public void onLocationChanged(Location myLocation) {
// Getting latitude of the current location
double latitude = myLocation.getLatitude();
// Getting longitude of the current location
double longitude = myLocation.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
//Adding new marker
now = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))
.position(latLng).title("New")
.snippet("Latitude:"+lat1+",Longitude:"+lon1)
);
// Showing the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(18));
//Draw polyline
drawPolygon(latitude, longitude);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
});
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mMap.getUiSettings().setZoomControlsEnabled(true);
}
private void drawPolygon(double latitude, double longitude) {
List<LatLng> polygon = new ArrayList<>();
//old lat and long
polygon.add(new LatLng(lat1, lon1));
//new lat and long
polygon.add(new LatLng(latitude,longitude));
mMap.addPolygon(new PolygonOptions()
.addAll(polygon)
.strokeColor(Color.YELLOW)
.strokeWidth(10)
.fillColor(Color.YELLOW)
);
lat1=latitude;
lon1=longitude;
}
}
은 GPS 추적이 구글지도에 경로를 실행/내 산책을 그리고도마다 내지도 활동이다 separately.this 내 경로를 저장해야합니다. 실제로 나는 사용자 단계, 거리, 시간을 카운트하는 만보계 앱을 개발 중입니다.
감사를 도울 수 있었지만 저장하는 방법을 좀 더 설명해 주시겠습니까 수 있기를 바랍니다. 저에게 있으면 제안 링크를주세요. –
이 경우에는 무엇을하고 싶은지 조금 더 설명 할 수 있습니다. 왜 그 위치를 저장하려고합니까? – Jamesp
위 내지도 활동을 업데이트했습니다. 그리고 내 사용자의 걷기/달리기/운전 경로의지도에 그려서 저장해야합니다. 내 애플 리케이션에서 엑서사이즈 세션을 열었을 때 내 거리, 시간 및 단계를 계산하고 Google지도에 내 사용자 경로를 그려야하며 마침을 클릭하면 저장하고 내 목록보기에 추가해야합니다. –