【发布时间】:2015-09-19 01:34:31
【问题描述】:
我有两个标记,一个是startLocation,另一个是stopLocation。 startLocation 将检测用户的当前位置,然后用户将步行,当他们停止时,他们会按停止,stopLocation 将被捕获为他们的新当前位置。当用户从startLocation 移动到stopLocation 时,我想绘制一条折线。
或者,也可以在创建开始和停止位置的标记后绘制折线 - 以更可实现的为准。
如何才能做到这一点?大多数答案都是指检索路线然后绘制折线,但这不是我想要的 - 我想获得用户的个性化路线。简而言之,我想记录用户走过的路线。我已经设法创建了两个标记:
btnStart = (Button) findViewById(R.id.btnStart);
btnStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Create Start Marker
// get current location
LocationManager locManager;
String context = Context.LOCATION_SERVICE;
locManager = (LocationManager) getSystemService(context);
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
c.setAltitudeRequired(false);
c.setBearingRequired(false);
c.setCostAllowed(true);
c.setPowerRequirement(Criteria.POWER_LOW);
String provider = locManager.getBestProvider(c, true);
Location loc = locManager.getLastKnownLocation(provider);
LatLng currentPosition = updateWithNewLocation(loc);
Marker startLocation = map.addMarker(new MarkerOptions()
.position(currentPosition)
.title("Start Location")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentPosition, 17));
}
});
btnStop = (Button) findViewById(R.id.btnStop);
btnStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Create Stop
// get current location
LocationManager locManager;
String context = Context.LOCATION_SERVICE;
locManager = (LocationManager) getSystemService(context);
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
c.setAltitudeRequired(false);
c.setBearingRequired(false);
c.setCostAllowed(true);
c.setPowerRequirement(Criteria.POWER_LOW);
String provider = locManager.getBestProvider(c, true);
Location loc = locManager.getLastKnownLocation(provider);
LatLng currentPosition = updateWithNewLocation(loc);
Marker stopLocation = map.addMarker(new MarkerOptions()
.position(currentPosition)
.title("Stop Location")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentPosition, 17));
// Draw dynamic line
}
});
现在我只需要在两个标记之间画一条线。谢谢!
【问题讨论】:
标签: google-maps routes google-maps-markers google-maps-android-api-2