使用google map integrtaion处理应用程序时。我有2个类RoutesData,LocationDistances
和一个活动类,我在其中实现一个方法getOverAllRoute()
来从一个方法返回的列表中选择一个LatLng对象RoutesData类,与特定LatLng对象的距离最小。
public class RoutesData{
...
...
public ArrayList<LatLng> allRoutePoints(){
ArrayList<LatLng> allPoints = new ArrayList<LatLng>(Arrays.asList(
//icPoints
new LatLng(33.582752, 73.044503),
new LatLng(33.595504, 73.050912),
//station
new LatLng(33.601097, 73.047798),
new LatLng(33.598755, 73.055607),
.. .
. .
));
return allPoints;
}
public class LocationDistances {
LatLng locs;
double distances;
}
public void getOverAllRoute(){
RoutesData rD = new RoutesData();
ArrayList<LatLng> mainRoutePoints = rD.allRoutePoints();
LocationDistances srcLocDis = new LocationDistances(); //to store location + distances from source
ArrayList<LocationDistances> srcLocDisList = new ArrayList();
//convert source latlng to location obj
Location srcLoc = new Location("");
srcLoc.setLatitude(dll.latitude);
srcLoc.setLongitude(dll.longitude);
// to compare distances from source location
for(int i =0;i<mainRoutePoints.size();i++){
Location mainPointsLoc = new Location("");
mainPointsLoc.setLatitude(mainRoutePoints.get(i).latitude);
mainPointsLoc.setLongitude(mainRoutePoints.get(i).longitude);
//store distances and location in arraylist
srcLocDis.locs = mainRoutePoints.get(i);
srcLocDis.distances = srcLoc.distanceTo(mainPointsLoc);
srcLocDisList.add(srcLocDis);
}
LocationDistances min=null;
for(LocationDistances x:srcLocDisList){
min=(min==null||x.distances<min.distances)?x:min;
Log.d("LocDist:",Double.toString(x.distances));
}
srcStartMin=min.locs;
Toast.makeText(this,srcStartMin.latitude+" "+srcStartMin.longitude, Toast.LENGTH_LONG).show();
}
但是当我从菜单项调用getOverAllRoutes()方法时,我的应用程序崩溃了。
答案 0 :(得分:0)
我怀疑它与
有关srcLoc.setLatitude(dll.latitude);
srcLoc.setLongitude(dll.longitude);
因为我没有看到初始化