【发布时间】: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