我想制作一个程序来计算一些地方到我的当前位置的距离,但是我的 googleMap.getMyLocation();无法正常工作。
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setCompassEnabled(false);
mylocation = googleMap.getMyLocation();
direction = new GMapV2Direction();
LatLng from, to;
from = new LatLng(-7.26071409, 112.80674726);
for(int i=0; i<lat.length; i++){
to = new LatLng(lat[i], lon[i]);
doc = direksi.getDocument(from, to, GMapV2Direction.MODE_DRIVING);
distance[i] = (double)direction.getDistanceValue(doc) / 1000;
}
我将一些地点的纬度和经度保存在lat[]和lon[]中。LatLng 'from' 是我的位置,而'to'则是我目的地的位置。 当我做出改变时,问题出现了。
from = new LatLng(-7.26071409, 112.80674726);
to
from = new LatLng(mylocation.getLatitude(), mylocation.getLongitude());
我希望在不打开Google Maps的情况下进行计算。当我点击地图按钮时,Google Maps将作为弹出窗口出现。因此,计算将在不打开Google Maps的情况下进行。
请帮帮我。