Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在CUNCENT位置和锁定位置之间绘制多段线_Android_Google Maps_Location_Draw_Polyline - Fatal编程技术网

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
函数