获取当前位置
问题描述:
我已经完成了创建一个向程序添加标记的android程序。 但我需要在MAP中显示CURRENT MY LOCATION。我知道这是通基于位置的服务做,但我不知道如何将其纳入我的计划获取当前位置
这里是我的onCreate命令
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//map
mapView = (MapView) findViewById(R.id.mapView);
//zoom
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
//Philippines coordinate
mc = mapView.getController();
String coordinates[] = {"10.952566007", "121.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(6);
mapOverlay = new MapOverlay();
listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
我有一个放置标记的的onTouchEvent 。所以没问题, 问题是我需要在程序开始时显示我的位置。它应该显示一个标记,上面写着“你在这里”或类似的东西。
p.s:我想我需要改变硬编码点到我目前的位置点,但我不知道该怎么做:
答
为了让您的手机的当前位置,我用
的LocationManager的LocationManager =(的LocationManager)this.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String bestProvider = locationManager.getBestProvider(criteria,true); 位置loc = locationManager.getLastKnownLocation(bestProvider);
限定在AndroidManifest.xml用途-权限这些 (使用细位置其他的东西)
在我的应用程序中,我希望将参数传递给地图意图,以便地图显示标记,但是找不到方法。按照Rick(谁不是Fred)的建议创建位置叠加层可能是要走的路线
另一个比你想要的更好的示例是anddev.org上的friend finder应用程序:http:/ /www.anddev.org/the_friend_finder_-_mapactivity_using_gps_-_part_i_-_ii-t93.html – RickNotFred 2010-02-23 13:39:41