所以,我有一个关于跟踪位置、获取纬度和经度值的项目。有时由于某种原因我必须手动更新数据。
- 在文本字段中插入新的纬度和经度
- 更新(按钮)
- 纬度和经度已更新
- map 已更新
这是我的预览:
- [TextField1] ... 纬度值 ...
- [TextField2] ... 经度值 ...
- [GMAP]
当我在文本字段中输入纬度和经度后,如何实时更新 map ?确认位置的准确性。
感谢任何帮助
我已经尝试过这个Action listener for a JTextField to change value in another textfield 但我不太明白。
if (salesman.getLatitude() != null && salesman.getLongitude() != null) {
latLng = new GLatLng(salesman.getLatitude(), salesman.getLongitude());
latLng = new GLatLng(-7.2587324, 112.7539422);
}
map = new GMap("map", ConstantUtils.googleMapApiKey);
map.setStreetViewControlEnabled(false);
map.setScaleControlEnabled(true);
map.setScrollWheelZoomEnabled(true);
map.setCenter(latLng);
map.setZoom(17);
map.setOutputMarkupId(true);
if (salesman.getLatitude() != null && salesman.getLongitude() != null) {
GMarkerOptions gMarkerOptions = new GMarkerOptions(map, latLng);
GMarker marker = new GMarker(gMarkerOptions);
map.addOverlay(marker);
}
最佳答案
取决于你如何定义
as i finish type
有两种方法可以做到这一点,例如在文本字段中输入数据后点击 ENTER 按钮,或者在文本字段中输入数据后单击其他位置。对于第一种情况,将 ActionListener
关联到文本字段;对于第二种情况,将 FocusListener
关联到文本字段。
JTextField inputField = new JTextField();
inputField.addActionListener(e -> {
String latAndLong = inputField.getText();
updateLocation(latAndLong);
});
inputField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String latAndLong = inputField.getText();
updateLocation(latAndLong);
}
});
private void updateLocation(String latAndLong) {
// your logic goes here
}
关于java - 获取值并在我打字时更新它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56538249/