Android 谷歌地图上的Gps坐标
嘿,伙计们,我再次需要你们的帮助Android 谷歌地图上的Gps坐标,android,Android,嘿,伙计们,我再次需要你们的帮助 我已经构建了地图应用程序,并且运行良好,现在我想查看我在地图中的当前位置。怎么办?请建议有不同的方法 您需要添加一个位置侦听器。有两种类型,一种是使用GPS本身(这在室内不起作用),另一种是使用网络 private LocationManager locationManager; public LocationListener locationListener; public LocationListener locationListener2; locati
我已经构建了地图应用程序,并且运行良好,现在我想查看我在地图中的当前位置。怎么办?请建议有不同的方法 您需要添加一个位置侦听器。有两种类型,一种是使用GPS本身(这在室内不起作用),另一种是使用网络
private LocationManager locationManager;
public LocationListener locationListener;
public LocationListener locationListener2;
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationListener2 = new MyLocationListener();
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, locationListener2);
//Location lister
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
mlongti = loc.getLongitude();
mlatiti = loc.getLatitude();
GeoPoint userLoc = new GeoPoint((int) (mlatiti * 1E6), (int) (mlongti * 1E6));
LItemizedOverlay itemizedoverlay = new LItemizedOverlay(selfImage,getParent(), "",userLoc,display);
try {
OverlayItem overlayitem = new OverlayItem(userLoc, "", "");
itemizedoverlay.addOverlay(overlayitem);
} catch (Exception e) {
e.printStackTrace();
}
List<Overlay> listOfOverlays = map.getOverlays();
listOfOverlays.add(itemizedoverlay);
MapController mc = map.getController();
mc.animateTo(userLoc);
mc.setZoom(10);
map.invalidate();
if(locationManager!=null && locationListener2 != null){
locationManager.removeUpdates(locationListener);
locationManager.removeUpdates(locationListener2);
locationManager= null;
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
私人位置管理器位置管理器;
公共场所监听器场所监听器;
公共场所监听器场所监听器2;
locationManager=(locationManager)getSystemService(Context.LOCATION\u服务);
locationListener=新建MyLocationListener();
locationListener2=新的MyLocationListener();
locationManager.RequestLocationUpdate(locationManager.GPS\提供程序,0,0,locationListener);
locationManager.RequestLocationUpdate(locationManager.NETWORK\u提供程序,0,0,locationListener2);
//位置列表器
私有类MyLocationListener实现LocationListener{
位置更改后的公共无效(位置loc){
mlongti=loc.getLongitude();
mlatiti=loc.getLatitude();
地质点userLoc=新的地质点((int)(姆拉蒂*1E6),(int)(姆拉蒂*1E6));
LItemizedOverlay itemizedoverlay=新的LItemizedOverlay(selfImage,getParent(),“”,userLoc,display);
试试{
OverlayItem OverlayItem=新的OverlayItem(userLoc,“,”);
itemizedoverlay.addOverlay(overlayitem);
}捕获(例外e){
e、 printStackTrace();
}
List listOfOverlays=map.getOverlays();
添加(itemizedoverlay);
MapController mc=map.getController();
动画师(userLoc);
mc.setZoom(10);
map.invalidate();
如果(locationManager!=null&&locationListener2!=null){
locationManager.RemoveUpdate(locationListener);
locationManager.RemoveUpdate(locationListener2);
locationManager=null;
}
}
公共无效onProviderDisabled(字符串提供程序){
//TODO自动生成的方法存根
}
公共无效onProviderEnabled(字符串提供程序){
//TODO自动生成的方法存根
}
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
//TODO自动生成的方法存根
}
}