如何自动绘制行上谷歌地图为用户移动入拉绳 [英] how to draw line on Google map as user move draw line automatically
问题描述
我开发这个应用程序,我要画在地图上轨线的Android应用程序
随着用户移动路径是自动绘制我找到了lat和长及其变化,每次
在位置改变,所以我想画在地图上线的时候,每次位置改变
我想这
公共无效onLocationChanged(地点){ 弦乐味精=位置:+ location.getLatitude()+,
+ location.getLongitude();
Toast.makeText(这一点,味精,Toast.LENGTH_LONG).show();
双new_lat = location.getLatitude();
双new_long = location.getLongitude();
drawTrack(new_lat,new_long,previous_lat,previous_long);
previous_lat = new_lat;
previous_long = new_long;
}
这是我做过什么:
公共无效onLocationChanged(地点){
prevLatitude =纬度;
prevLongitude =经度;
纬度= location.getLatitude();
经度= location.getLongitude();
的latLng =新的经纬度(纬度,经度); 的PolylineOptions pOptions =新的PolylineOptions()
.WIDTH(5)
。颜色(Color.GREEN)
.geodesic(真);
对于(INT Z = 0; z,其中,routePoints.size(); Z ++){
点的LatLng = routePoints.get(Z);
pOptions.add(点);
}
行= googleMap.addPolyline(pOptions);
routePoints.add(的latLng);
}
在路线点是经纬度的的ArrayList,线条折线和GoogleMap的是着,当然,你的GoogleMap的。因此,在类中添加的开头:
私人GoogleMap的GoogleMap的;
私人折线线;
私人的ArrayList<&经纬度GT;路线点;
和在OnCreate添加:
路线点=新的ArrayList<&经纬度GT;();
希望这可以帮助你:!)
I am developing an android application in this application i want to draw path line on map
As user move path is draw automatically i found the lat and long and its change every time
When location is changed so i want to draw line on map when every time location is changed
i tried this
public void onLocationChanged(Location location) {
String msg = "Location:" + location.getLatitude() + ","
+ location.getLongitude();
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
double new_lat = location.getLatitude();
double new_long = location.getLongitude();
drawTrack(new_lat, new_long, previous_lat, previous_long);
previous_lat = new_lat;
previous_long = new_long;
}
This is what I did:
public void onLocationChanged(Location location) {
prevLatitude = latitude;
prevLongitude = longitude;
latitude = location.getLatitude();
longitude = location.getLongitude();
latLng = new LatLng(latitude, longitude);
PolylineOptions pOptions = new PolylineOptions()
.width(5)
.color(Color.GREEN)
.geodesic(true);
for (int z = 0; z < routePoints.size(); z++) {
LatLng point = routePoints.get(z);
pOptions.add(point);
}
line = googleMap.addPolyline(pOptions);
routePoints.add(latLng);
}
in which routePoints is an arraylist of LatLng's, line is your Polyline and googleMap is, ofcourse, your GoogleMap. So on the beginning of the class add:
private GoogleMap googleMap;
private Polyline line;
private ArrayList<LatLng> routePoints;
and in the onCreate add:
routePoints = new ArrayList<LatLng>();
hope this helps for you!:)
这篇关于如何自动绘制行上谷歌地图为用户移动入拉绳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!