Android 在谷歌地图上移动图标

Android 在谷歌地图上移动图标,android,google-maps,Android,Google Maps,我在这里搜索过类似的问题,但没有一个对我有帮助。 我有一个在地图上运行的应用程序,它显示了用户所走的路径和一个以“police”形式显示的图标。我现在想要的是这个图标将地图移到我身后。因此,我创建了一个方法(stable),根据用户的当前位置、图标和地图的位置计算一个新点。这个方法是可行的,但问题是当我运行应用程序时,图标只移动一次,因为他的位置没有更新 以下是我的部分代码: public void onMyLocationChange(Location location) { doub

我在这里搜索过类似的问题,但没有一个对我有帮助。 我有一个在地图上运行的应用程序,它显示了用户所走的路径和一个以“police”形式显示的图标。我现在想要的是这个图标将地图移到我身后。因此,我创建了一个方法(stable),根据用户的当前位置、图标和地图的位置计算一个新点。这个方法是可行的,但问题是当我运行应用程序时,图标只移动一次,因为他的位置没有更新

以下是我的部分代码:

public void onMyLocationChange(Location location) {
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    lat = String.valueOf(latitude);
    longi = String.valueOf(longitude);

    posCurrent = new LatLng(latitude, longitude);
    posAtuais.add(posCurrent);

    posInicial = posAtuais.get(0);
    Marker marker = map.addMarker(new MarkerOptions().position(posInicial));

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(posCurrent, 19));

    PolylineOptions options = new PolylineOptions().width(5).color(mudaLinhaCor(heart_rate)).geodesic(true);
    for (int z = 0; z < posAtuais.size(); z++) {
        LatLng point = posAtuais.get(z);
        options.add(point);
    }
    line = map.addPolyline(options);

    LatLng posPolice = stalk(posCurrent, POLICE, map);
    Marker init = map.addMarker(new MarkerOptions().position(posPolice)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.police)));


}

    //A method that computes a new position
public LatLng stalk(LatLng player,LatLng police,GoogleMap mapView){
    Projection projection = mapView.getProjection(); 
    Point pointInicial = new Point(); //police
    pointInicial = projection.toScreenLocation(police);
    Point pointFinal = new Point(); //player
    pointFinal = projection.toScreenLocation(player);
    double y=0.2;
    int x=0;

    if((pointInicial.x==pointFinal.x)){
        y=pointInicial.y+1;
    }else{
        double m=(pointFinal.y-pointInicial.y)/(pointFinal.x-pointInicial.x);
        double b=pointInicial.y-(m*pointInicial.x);
        int i=1;

        while(y != (int)y){
            if(pointInicial.x<pointFinal.x){
                x=pointInicial.x+i;
                //System.out.println("entrou no x<xfnal: "+x);
            }
            else if(pointInicial.x>pointFinal.x){
                //System.out.println("entrou no x>xfnal");
                x=pointInicial.x-i;
            }
            y=m*x+b;
            //System.out.println("y: : "+y);
            i++;
        }
    }
    return projection.fromScreenLocation(new Point(x, (int) y)); 
}
public void onMyLocationChange(位置){
双纬度=location.getLatitude();
double longitude=location.getLongitude();
lat=字符串的值(纬度);
longi=字符串。valueOf(经度);
posCurrent=新纬度(纬度、经度);
posAtuais.add(posCurrent);
posinical=posAtuais.get(0);
Marker Marker=map.addMarker(新MarkerOptions().position(posinical));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(posCurrent,19));
PolylineOptions=新的PolylineOptions().宽度(5).颜色(mudaLinhaCor(心率)).测地线(真);
对于(intz=0;zxfnal”);
x=点位x-i;
}
y=m*x+b;
//System.out.println(“y::”+y);
i++;
}
}
返回投影。从屏幕位置(新点(x,(int)y));
}

有人可以帮助我。

在您的活动中实现onmarkerdragstener

@Override
public void onMarkerDragStart(Marker arg0) {
    markerOptions.position(latLng);
}
@Override
public void onMarkerDragEnd(Marker arg0) {
    myMap.clear();
    latLng = arg0.getPosition();
    markerOptions.position(latLng);
    Marker marker = myMap.addMarker(markerOptions);


}

我必须在onMyLocationChange中调用MarkerDragStart和onMarkerDragEnd??我不太明白这是怎么回事。。。