जावा स्विंग में जियोकोडर के साथ कोई समस्या

वोट
0

नमस्कार, मैं जावा डेस्कटॉप में एक शैक्षिक परियोजना के लिए एक प्रणाली का निर्माण कर रहा हूँ। इस परियोजना में, मैं भौगोलिक निर्देशांक (अक्षांश और देशांतर) उन्हें डेटाबेस में स्टोर करने के लिए करने के लिए इस पते एक पते ( 5 वीं एवेन्यू, न्यूयॉर्क की तरह) को प्राप्त करने और परिवर्तित करने के लिए की जरूरत है। ये निर्देशांक एक नक्शे पर प्रदर्शित किया जाएगा।

मैं JxMaps एपीआई का उपयोग कर रहा हूँ, लेकिन मैं उदाहरण जियोकोडर कोड उनके द्वारा उपलब्ध कराया अनुकूलन नहीं कर सकते। कोई फर्क नहीं पड़ता कि मुझे क्या करना, कोड सिर्फ काम नहीं करता। हालांकि, उदाहरण में, यह काम करता है।

मेरे कोड (है कि पैकेज के मॉडल पर है) से एक टुकड़ा इस प्रकार है:

package model;
import com.teamdev.jxmaps.GeocoderCallback;
import com.teamdev.jxmaps.GeocoderRequest;
import com.teamdev.jxmaps.GeocoderResult;
import com.teamdev.jxmaps.GeocoderStatus;
import com.teamdev.jxmaps.InfoWindow;
import com.teamdev.jxmaps.LatLng;
import com.teamdev.jxmaps.Map;
import com.teamdev.jxmaps.Marker;
import com.teamdev.jxmaps.swing.MapView;

import dao.tableMapa;

public class Geocoder extends MapView {

private boolean performGeocode(String text) {
    public boolean s;
    // Getting the associated map object
    final Map map = getMap();
    // Creating a geocode request
    GeocoderRequest request = new GeocoderRequest();
    // Setting address to the geocode request
    request.setAddress(text);

    // Geocoding position by the entered address
    getServices().getGeocoder().geocode(request, new GeocoderCallback(map) {
        @Override
        public void onComplete(GeocoderResult[] results, GeocoderStatus status) {
            // Checking operation status
            boolean r=false;
            if ((status == GeocoderStatus.OK) && (results.length > 0)) {
                // Getting the first result
                GeocoderResult result = results[0];
                // Getting a location of the result
                LatLng location = result.getGeometry().getLocation();

                tableMapa p=new tableMapa();
                r = p.Geocodification(location, text);
            }
        }
    });
  }
}

और यह दाव पैकेज पर है:

package dao;

import java.sql.Connection;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import com.teamdev.jxmaps.LatLng;
import model.ModeloMySql;
import model.pontoColeta;
import controller.fabricaConexao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class tableMapa {
    private ModeloMySql modelo = null;

    public tableMapa() {

        modelo = new ModeloMySql();
        modelo.setDatabase(projeto);
        modelo.setServer(localhost);
        modelo.setUser(root);
        modelo.setPassword(1234);
        modelo.setPort(3306);
    }

    public boolean Geocodification(LatLng location, String address){
        Boolean status = true;

        Connection con;
        con = fabricaConexao.getConnection(modelo);

        if (con == null) {
            JOptionPane.showMessageDialog(null, Failed to connect);
        }

        //String sql = UPDATE TABLE set(latitude=+location.getLat()+,longitude=+location.getLng()+ from pontocoleta where address=+address+;;
        String sql = UPDATE pontoColeta set latitude = ? ,longitude = ? from pontocoleta where address = ?;

        try {
            PreparedStatement statement = con.prepareStatement(sql);

            statement.setDouble(1, location.getLat());
            statement.setDouble(2, location.getLng());
            statement.setString(3, address);
            statement.executeUpdate();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fabricaConexao.closeConnection(con);
            return false;
        }

        return true;
    }

    public ArrayList<pontoColeta> pontosSelect() {
        Boolean status = true;

        Connection con;
        con = fabricaConexao.getConnection(modelo);

        // testa se conseguiu conectar
        if (con == null) {
            JOptionPane.showMessageDialog(null, Failed to connect);
        }

        ArrayList<pontoColeta> pontos = new ArrayList<>();

        String sql = SELECT * from pontocoleta;
        pontoColeta p;

        try {
            PreparedStatement statement = con.prepareStatement(sql);
            ResultSet result = statement.executeQuery();

            while(result.next()){
                    p = new pontoColeta();
                    LatLng c = new LatLng(result.getDouble(latitude), result.getDouble(longitude));
                    p.setCoordinates(c);
                    p.setIdPonto(result.getInt(idPonto));
                    p.setDescription(result.getString(description));
                    p.setAddress(result.getString(address));
                    p.setPhone(result.getString(phone));  
                    pontos.add(p);

                } 
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            status = false;
        } finally {
            // Fecha a conexao
            fabricaConexao.closeConnection(con);
        }
        return pontos;
    }
}

मैं यह काम नहीं कर सकता। कृपया मेरी मदद करें!!

27/11/2017 को 18:47
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
0

बशर्ते कोड एक हिस्सा है जहाँ आप बुला रहे हैं नहीं है performGeocode। कृपया जाँचें कि यह की पूरी आरंभीकरण के बाद कहा जाता है MapView। मैं उस पर कॉल करने के लिए सलाह देते हैं onMapReadyघटना। कृपया एक नज़र एक उदाहरण नीचे प्रदान ले:

MapView mapView = new MapView(); 

mapView.setOnMapReadyHandler(new MapReadyHandler() {
   @Override
   public void onMapReady(MapStatus status) {
       ...
       performGeocode(...);
   });
28/11/2017 को 07:41
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more