0

So, i have a project about tracking location, get the latitude and longitude value. Sometimes i have to manually update the Data for a some reason.

  1. Insert the new Lat and Long in the TextField
  2. UPDATE (BUTTON)
  3. Lat & Long Updated
  4. MAP Updated

here is my Preview :

  • [TextField1] ... Latitude Value ...
  • [TextField2] ... Longitude Value ...
  • [GMAP]

How can I get live update the MAP as i finish type the Lat & Long in the TextField? To confirm the Location's right accuracy.

any help is appreciated

I've tried this Action listener for a JTextField to change value in another textfield but i'm not quite understand.

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

        }
Aldo Tobing
  • 13
  • 1
  • 4

1 Answers1

0

Depends on how you define

as i finish type

There can be two ways to do so, like hitting ENTER button after entering data in the text field or clicking somewhere else after typing the text field. For the first case, associate a ActionListener to the text field; and for the second case associate a FocusListener to the text field.

        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
    }
GirishB
  • 134
  • 7