【问题标题】:google map in codename one代号一的谷歌地图
【发布时间】:2016-12-09 12:58:12
【问题描述】:

我正在使用代号 one 开发一个包含谷歌地图的应用程序,我希望当我打开应用程序时它会获取我当前的位置我该怎么做,这是我拥有的代码。

    static Location lastKnownLocation;
@Override
protected void beforeMap(Form f) {
    MapContainer mapContainer = new MapContainer(new GoogleMapsProvider("AIzaSyCyy_vOWn3DvR3Y8pzAWUmKTzBaDa81Tfc"));
    lastKnownLocation = LocationManager.getLocationManager().getLastKnownLocation();
    Style s = new Style();
    s.setBgTransparency(0);
    s.setFgColor(0);
    mapContainer.addMarker(FontImage.createMaterial(FontImage.MATERIAL_MY_LOCATION, s).toEncodedImage(), new Coord(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()), "", "", evt -> {
        ToastBar.showErrorMessage(lastKnownLocation.toString());
    });
    mapContainer.addTapListener(evt -> {
        Coord coord = mapContainer.getCoordAtPosition(evt.getX(), evt.getY());
        mapContainer.addMarker(FontImage.createMaterial(FontImage.MATERIAL_LOCATION_ON, s).toEncodedImage(), coord, "", "", null);
    });

    f.add(BorderLayout.CENTER, mapContainer);
     FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_ADD);
    fab.addActionListener(e -> {
        ParseObject object = ParseObject.create("Geo");
        object.put("current", new ParseGeoPoint(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()));
        if (ParseUser.getCurrent() != null)
            object.put("user", ParseUser.getCurrent());
        try {
            object.save();
            ToastBar.showErrorMessage("Geo Sent");
        } catch (ParseException ex) {
            ex.printStackTrace();
            ToastBar.showErrorMessage(ex.getMessage());
        }
    });
    fab.bindFabToContainer(f.getContentPane());
}

}

【问题讨论】:

    标签: android google-maps codenameone


    【解决方案1】:

    请注意,在设备上将使用并突出显示您的当前位置,因为设备运行本机地图,而模拟器运行模拟。

    话虽如此,您可以从 LocationManager 类中获取您的位置。

    例如:

    Location position = LocationManager.getLocationManager().getCurrentLocationSync();
    

    【讨论】:

    • 谢谢 Shai,它起作用了,现在我如何改进相同的代码,以便在我移动时显示我的位置的标记移动,以及如何自动放大我的位置。
    • 您可以添加/删除标记,我建议使用位置侦听器而不是这种同步方法。您也可以使用 API 控制相机位置
    猜你喜欢
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多