Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 代号为1的谷歌地图_Android_Google Maps_Codenameone - Fatal编程技术网

Android 代号为1的谷歌地图

Android 代号为1的谷歌地图,android,google-maps,codenameone,Android,Google Maps,Codenameone,我用代号一开发一个应用程序,其中有谷歌地图,我想当我打开应用程序,它得到我的当前位置,我怎么能做到这一点,这是我的代码 static Location lastKnownLocation; @Override protected void beforeMap(Form f) { MapContainer mapContainer = new MapContainer(new GoogleMapsProvider("AIzaSyCyy_vOWn3DvR3Y8pzAWUmKTzBaD

我用代号一开发一个应用程序,其中有谷歌地图,我想当我打开应用程序,它得到我的当前位置,我怎么能做到这一点,这是我的代码

    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());
}

}

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

已经说过,你可以从课堂上得到你的位置

例如:

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

谢谢Shai,它成功了,现在我如何改进相同的代码,以便显示我位置的标记在我移动时移动,以及如何自动放大我的位置。您可以添加/删除标记,我建议使用位置侦听器而不是这种同步方法。您还可以使用API控制相机位置