从Sql server 2014添加Lat和Long的多个标记

时间:2016-05-11 12:22:18

标签: android google-maps-markers

我想从Sql server 2014添加100个带Lat和Long的标记 我的标记不会在地图上显示。我不知道是什么问题。

请帮我改进代码或告诉我更好的方法

这是我的代码

public class Location {


    private String latlong_ID, latlong_nome;
    private Double latlong_Lat, latlong_Long;

    public Location(String latlong_ID, String latlong_nome,Double latlong_Lat,Double latlong_Long) {
        this.latlong_ID = latlong_ID;
        this.latlong_nome = latlong_nome;
        this.latlong_Lat = latlong_Lat;
        this.latlong_Long = latlong_Long;

    }

    public String getLatlong_ID() {
        return latlong_ID;
    }

    public void setLatlong_ID(String latlong_ID) {
        this.latlong_ID = latlong_ID;
    }

    public String getLatlong_nome() {
        return latlong_nome;
    }

    public void setLatlong_nome(String latlong_nome) {
        this.latlong_nome = latlong_nome;
    }

    public Double getLatlong_Lat() {
        return latlong_Lat;
    }

    public void setLatlong_Lat(Double latlong_Lat) {
        this.latlong_Lat = latlong_Lat;
    }

    public Double getLatlong_Long() {
        return latlong_Long;
    }

    public void setLatlong_Long(Double latlong_Long) {
        this.latlong_Long = latlong_Long;
    }
}


public class LocationLatLong extends AsyncTask<String, String, String> {
        String z = "";

       // List<Location> locationList = new ArrayList<Location>();


        @Override
        protected void onPostExecute(String s) {

            for(int i = 0 ; i < location.size() ; i++ ) {

                createMarker(location.get(i).getLatlong_Lat(),location.get(i).getLatlong_Long(),location.get(i).getLatlong_nome());

            }
            super.onPostExecute(s);
        }



        @Override
        protected String doInBackground(String... params) {

            try {
                Connection con = connectionClass.CONN();
                if (con == null) {
                    z = "Error in connection with SQL server";
                } else {
                    String query = "select * from LojaLocation";
                    PreparedStatement ps = con.prepareStatement(query);
                    ResultSet rs = ps.executeQuery();


                    while (rs.next()) {

                        String LatLongID = rs.getString("Id");
                        String LatLongnome = rs.getString("Nome");
                        String LatLongLat = rs.getString("Latitude");
                        String LatLongLong = rs.getString("Longitudi");

                        Double LatLong_Lat1 = Double.valueOf(LatLongLat);
                        Double LatLong_Long1 = Double.valueOf(LatLongLong);




                        Location p = new Location(LatLongID, LatLongnome, LatLong_Lat1,LatLong_Long1 );

                        location.add(p);

                    }



                    z = "Success";
                }
            } catch (Exception ex) {
                z = "Error retrieving data from table";

            }
            return z;
        }
protected void createMarker(Double latitude, Double longitude, String title) {

        map.addMarker(new MarkerOptions()
                .position(new LatLng(latitude, longitude))
                .title(title)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_map_marker)));
}

1 个答案:

答案 0 :(得分:0)

在Map对象上执行此操作以添加Marker

LatLng latLong = new LatLng(latitude, longitude); 
 googleMap.addMarker(new MarkerOptions()
                    .position(latLng)
                    .title("You"));