iOS中的地图上的位置错误

时间:2016-04-18 17:40:49

标签: java ios google-maps codenameone locationmanager

我尝试用iOS代号实现一个​​小应用程序。我在dialoge中显示了Google地图。我想在嵌入式地图上显示我的实际和真实位置。我在0N 0E附近的地图上显示 - 在海洋的某个地方。这是我使用的代码:

private void putMeOnMap(MapComponent map) {
    Location loc;
    try {
        loc = LocationManager.getLocationManager().getCurrentLocation();
        lastLocation = new Coord(loc.getLatitude(), loc.getLongitude());
        Image i = Image.createImage(10, 10, 0xff00ff00); //("/red_pin.png");
        PointsLayer pl = new PointsLayer();
        pl.setPointIcon(i);
        PointLayer p = new PointLayer(lastLocation, "aktueller Standort", i);
        p.setDisplayName(true);
        pl.addPoint(p);
        pl.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                PointLayer p = (PointLayer) evt.getSource();
                System.out.println("pressed " + p);

                Dialog.show("Details", "Du bist hier" + "\n" + p.getLatitude() + "|" + p.getLongitude(), "Ok", null);
            }
        });
        map.addLayer(pl);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

在iOS应用中使用时,您需要明确询问并接受位置跟踪。

看起来像这样:

    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.locationServicesEnabled
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()

    ...

    var shouldIAllow = false

    switch status {
    case CLAuthorizationStatus.Restricted:
        locationStatus = "Restricted Access to location"
    case CLAuthorizationStatus.Denied:
        locationStatus = "User denied access to location"
    case CLAuthorizationStatus.NotDetermined:
        locationStatus = "Status not determined"
    default:
        locationStatus = "Allowed to location Access"
        shouldIAllow = true
    }

    if (shouldIAllow == true) {
        NSLog("Location to Allowed")
        // Start location services
        locationManager.startUpdatingLocation()
    } else {
        NSLog("Denied access: \(locationStatus)")
    }

答案 1 :(得分:0)

我建议使用native mapping,它在设备上看起来要好得多,并且还会突出显示您的位置。

您还应该使用getCurrentLocationSync()而不是getCurrentLocation()。请注意,您必须按照here所述定义构建提示ios.locationUsageDescription