Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package user.example.com.roadworks3;
- import android.annotation.SuppressLint;
- import android.os.StrictMode;
- import android.support.v4.app.FragmentActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Toast;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.OnMapReadyCallback;
- import com.google.android.gms.maps.SupportMapFragment;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.android.gms.maps.model.MarkerOptions;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
- Double loc_long, loc_lat;
- List<Map<String, String>> data = null;
- private GoogleMap mMap;
- /****************************Database Connection Variables*************************************/
- ConnectionClass connectionclass;
- String usernameS;
- String datets;
- String call, db, un, passwords;
- Connection connect;
- ResultSet rs;
- @SuppressLint("NewApi")
- private Connection CONN(String _user, String _pass, String _DB, String _server)
- {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- Connection conn = null;
- String ConnURL = null;
- try{
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- ConnURL = "jdbc:jtds:sqlserver://" + _server + ";"
- + "databaseName=" + _DB + ";user=" + _user + ";password=" + _pass + ";";
- conn = DriverManager.getConnection(ConnURL);
- }catch (SQLException se){
- Log.e("ERROR", se.getMessage());
- }catch (ClassNotFoundException e){
- Log.e("ERROR", e.getMessage());
- }catch (Exception e){
- Log.e("ERROR", e.getMessage());
- }
- return conn;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_maps);
- // Obtain the SupportMapFragment and get notified when the map is ready to be used.
- SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
- .findFragmentById(R.id.map);
- mapFragment.getMapAsync(this);
- connectionclass = new ConnectionClass();
- call = connectionclass.getIp();
- un = connectionclass.getUn();
- passwords = connectionclass.getPassword();
- db = connectionclass.getDb();
- connect = CONN(un, passwords, db, call);
- String querycmd = "select * from trafficNews2";
- try {
- Statement statement = connect.createStatement();
- rs = statement.executeQuery(querycmd);
- /*List<Map<String, String>> data = null;*/
- data = new ArrayList<Map<String, String>>();
- while (rs.next()) {
- Map<String, String> datanum = new HashMap<String, String>();
- datanum.put("A", rs.getString("streetName"));
- datanum.put("B", rs.getString("startTime"));
- datanum.put("C", rs.getString("stopTime"));
- datanum.put("D", rs.getString("notes"));
- datanum.put("E", rs.getString("loc_long"));
- datanum.put("F", rs.getString("loc_lat"));
- datanum.put("G", rs.getString("start_long"));
- datanum.put("H", rs.getString("start_lat"));
- datanum.put("I", rs.getString("stop_long"));
- datanum.put("J", rs.getString("stop_lat"));
- data.add(datanum);
- loc_long = Double.parseDouble(datanum.get("E"));
- loc_lat = Double.parseDouble(datanum.get("F"));
- }
- } catch (SQLException e){
- Toast.makeText(MapsActivity.this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
- }
- }
- /**
- * Manipulates the map once available.
- * This callback is triggered when the map is ready to be used.
- * This is where we can add markers or lines, add listeners or move the camera. In this case,
- * we just add a marker near Sydney, Australia.
- * If Google Play services is not installed on the device, the user will be prompted to install
- * it inside the SupportMapFragment. This method will only be triggered once the user has
- * installed Google Play services and returned to the app.
- */
- @Override
- public void onMapReady(GoogleMap googleMap) {
- mMap = googleMap;
- // Add a marker in Sydney and move the camera
- LatLng sydney = new LatLng(-34, 151);
- mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
- mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
- LatLng loc = new LatLng(loc_long,loc_lat);
- mMap.addMarker(new MarkerOptions().position(loc).title("Fuck that shit"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement