Java Android locationlistener不';无法在android设备上工作

Java Android locationlistener不';无法在android设备上工作,java,android,google-maps,location,listener,Java,Android,Google Maps,Location,Listener,当我在模拟器中使用DDMS控件时,我的位置侦听器工作,但当我将其部署到手机上时,它不再工作。我的代码如下 public class hoosheerAndroidAct extends MapActivity implements LocationListener { /** Called when the activity is first created. */ MapController mc; public static MapView gMapView = nu

当我在模拟器中使用DDMS控件时,我的位置侦听器工作,但当我将其部署到手机上时,它不再工作。我的代码如下

public class hoosheerAndroidAct extends MapActivity implements LocationListener {
    /** Called when the activity is first created. */
    MapController mc;
    public static MapView gMapView = null;
    GeoPoint p = null;
    static double latitude, longitude;
    MyLocationOverlay myLocationOverlay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen1);

        // Creating and initializing Map
        gMapView = (MapView) findViewById(R.id.mapview);
        p = new GeoPoint((int) (latitude * 1E6),
                (int) (longitude * 1E6));
        gMapView.setSatellite(true);
        gMapView.setBuiltInZoomControls(true);
        mc = gMapView.getController();
        mc.setCenter(p);

        mc.setZoom(11);
        myLocationOverlay = new MyLocationOverlay(this, gMapView);
        gMapView.getOverlays().add(myLocationOverlay);
        list = gMapView.getOverlays();
        list.add(myLocationOverlay);

        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 5.0f,
                this);

    }
实现LocationListener的方法

public void onLocationChanged(Location location) {
        if (location != null) {
            GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),
                    (int) (location.getLongitude() * 1E6));
            mc.animateTo(point);
            connect("http://api.foursquare.com/v1/venues.json?geolat="
                    + location.getLatitude() + "&geolong="
                    + location.getLongitude());
            Drawable marker = getResources().getDrawable(R.drawable.marker);
            gMapView.getOverlays().add(new SitesOverlay(marker));

        }
    }

    public void onProviderDisabled(String provider) {
        // required for interface, not used
    }

    public void onProviderEnabled(String provider) {
        // required for interface, not used
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // required for interface, not used
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }


我有什么遗漏吗-(

这是因为当您的设备无法找到位置时,它会返回默认位置0,0。最好通过检查其他应用程序(如设备的地图应用程序)来检查设备gps连接。如果gps无法找到信号,则Google maps将默认为网络位置提供商,以便测试可以返回没有gps信号的位置。我会推荐GPS Status作为一个好的免费应用程序。我唯一能想到的另一件事是确保你能清楚地看到天空。

也许你正在室内测试,无法获得GPS信息。尝试更改LocationManager.GPS\u提供程序-->LocationManager.NETWORK\u提供程序。

我遇到了类似的问题,并尝试了编程中的一切。我阅读了关于谷歌使用相同的其他传感器来查找位置。我甚至在谷歌地图中找到了位置监听器不起作用的移动设备。当我检查设置时,我成功地打开了电池节电,位置监听器启动。在其他一些位置不起作用的设备上,我打开了buttery Save并显示位置。我不知道为什么会这样但是buttery可能会保存你的应用程序。

你说它不工作是什么意思?它在设备上与在模拟器上有什么不同?@DHall当我在模拟器上运行它时,我可以模拟DDMS中的位置,当部署到手机上时,它会将坐标设置为(0,0)我看不出你在哪里为这个位置分配了一个侦听器……同样,你也知道,在java中,你可以将1000000写为1E6,如果可以缩短的话,不要在那里放长的数字。@Sunil我已经检查了提取用户当前位置的内置映射你注意到joxTraex注释了吗,请立即插入你的locationlistener分配代码我知道了没有设备,因此我无法测试您的代码,但尝试将RequestLocationUpdate更改为lm.RequestLocationUpdate(LocationManager.GPS_PROVIDER,0,0,此);@Sunil我已在许多设备上测试了更改,但仍然没有成功:-(使用它而不是我最初拥有的结果是什么?我认为范围将是一个问题。在我的情况下,当我在公司测试我的设备时,我没有获得位置。但当我离开gps提供商时,我正在更新位置。你的地图应用程序可能会显示最后一个已知位置。我必须在早上到外面试试:-)为什么它不能在室内工作?卫星广播的短波信号无法穿透稠密的物质…例如房屋或许多针叶树。仍然无法成功找到用户位置,这让我陷入困境(0,0):-(我认为你应该简化你的代码或创建一个新的简单程序来显示用户的位置变化。这样你就可以确定是哪部分代码导致了这个问题。对不起,我没有一个简单的答案:/只是检查一下-你在格林威治以南的赤道上吗?:)