Android 在CUNCENT位置和锁定位置之间绘制多段线
我这里有个问题。我有谷歌地图和我自己的位置和锁定的位置现在锁定的位置是没有问题的,但目前的位置是。我想在这两个位置之间画一条线。他们都工作,所以没有问题。唯一的问题是: 多段线代码Android 在CUNCENT位置和锁定位置之间绘制多段线,android,google-maps,location,draw,polyline,Android,Google Maps,Location,Draw,Polyline,我这里有个问题。我有谷歌地图和我自己的位置和锁定的位置现在锁定的位置是没有问题的,但目前的位置是。我想在这两个位置之间画一条线。他们都工作,所以没有问题。唯一的问题是: 多段线代码 Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(location.getLatitude(), location.getLongitude()), new LatLng(52.0193
Polyline line = googleMap.addPolyline(new PolylineOptions()
.add(new LatLng(location.getLatitude(), location.getLongitude()),
new LatLng(52.01936, 4.39113))
.width(5)
.color(Color.RED));
因此,我的想法是将这两个链接起来,但我不知道要在
.add(new LatLng(location.getLatitude(), location.getLongitude())
这是我将当前位置坐标显示为文本视图的代码:
@Override
public void onLocationChanged(Location location) {
TextView tvLocation = (TextView) findViewById(R.id.tv_location);
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// Setting latitude and longitude in the TextView tv_location
tvLocation.setText("Latitude:" + latitude + ", Longitude:"+ longitude );
有人知道我该怎么做吗?如果你说的不够清楚,我会解释得更清楚 您需要将位置值从
onLocationChanged
提取到类变量。例如:
public Location curLoc=new Location()代码>
然后在onLocationChanged()
中,将location
的值传递到curLoc
,如下所示:curLoc=location
然后在多段线上,使用curLoc.getLatitude()
和curLoc.getLatitude()
我希望这会有帮助,祝你好运^有什么问题吗?添加(新的LatLng(location.getLatitude(),location.getLongitude())有什么问题
?我不知道,他没有写完整的代码。在我的分析中,他很困惑,因为位置
内部多段线没有用他的当前位置更新。抱歉,伙计们,反应太晚了,我现在解决了这个问题。我唯一要补充的是:公共位置lastLocation;
哈哈,我不知道这一点真是愚蠢@reidzeibel true我仍然需要用我的当前位置更新我的多段线,如果我完全关闭应用程序,它只会更新多段线,但我想我只需要将多段线代码放入我的onLocationChanged
函数或/和创建onResume
函数