Advertisement
Guest User

tanapou with love to loulis

a guest
Apr 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. package user.example.com.roadworks3;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.os.StrictMode;
  5. import android.support.v4.app.FragmentActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Toast;
  10.  
  11. import com.google.android.gms.maps.CameraUpdateFactory;
  12. import com.google.android.gms.maps.GoogleMap;
  13. import com.google.android.gms.maps.OnMapReadyCallback;
  14. import com.google.android.gms.maps.SupportMapFragment;
  15. import com.google.android.gms.maps.model.LatLng;
  16. import com.google.android.gms.maps.model.MarkerOptions;
  17.  
  18. import java.sql.Connection;
  19. import java.sql.DriverManager;
  20. import java.sql.ResultSet;
  21. import java.sql.SQLException;
  22. import java.sql.Statement;
  23. import java.util.ArrayList;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27.  
  28. public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
  29. Double loc_long, loc_lat;
  30. List<Map<String, String>> data = null;
  31. private GoogleMap mMap;
  32.  
  33. /****************************Database Connection Variables*************************************/
  34.  
  35. ConnectionClass connectionclass;
  36. String usernameS;
  37. String datets;
  38. String call, db, un, passwords;
  39. Connection connect;
  40. ResultSet rs;
  41.  
  42. @SuppressLint("NewApi")
  43. private Connection CONN(String _user, String _pass, String _DB, String _server)
  44. {
  45. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  46. StrictMode.setThreadPolicy(policy);
  47. Connection conn = null;
  48. String ConnURL = null;
  49. try{
  50. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  51. ConnURL = "jdbc:jtds:sqlserver://" + _server + ";"
  52. + "databaseName=" + _DB + ";user=" + _user + ";password=" + _pass + ";";
  53. conn = DriverManager.getConnection(ConnURL);
  54. }catch (SQLException se){
  55. Log.e("ERROR", se.getMessage());
  56. }catch (ClassNotFoundException e){
  57. Log.e("ERROR", e.getMessage());
  58. }catch (Exception e){
  59. Log.e("ERROR", e.getMessage());
  60. }
  61. return conn;
  62. }
  63.  
  64.  
  65. @Override
  66. protected void onCreate(Bundle savedInstanceState) {
  67. super.onCreate(savedInstanceState);
  68. setContentView(R.layout.activity_maps);
  69. // Obtain the SupportMapFragment and get notified when the map is ready to be used.
  70. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  71. .findFragmentById(R.id.map);
  72. mapFragment.getMapAsync(this);
  73.  
  74. connectionclass = new ConnectionClass();
  75. call = connectionclass.getIp();
  76. un = connectionclass.getUn();
  77. passwords = connectionclass.getPassword();
  78. db = connectionclass.getDb();
  79. connect = CONN(un, passwords, db, call);
  80. String querycmd = "select * from trafficNews2";
  81. try {
  82. Statement statement = connect.createStatement();
  83.  
  84. rs = statement.executeQuery(querycmd);
  85. /*List<Map<String, String>> data = null;*/
  86. data = new ArrayList<Map<String, String>>();
  87. while (rs.next()) {
  88. Map<String, String> datanum = new HashMap<String, String>();
  89. datanum.put("A", rs.getString("streetName"));
  90. datanum.put("B", rs.getString("startTime"));
  91. datanum.put("C", rs.getString("stopTime"));
  92. datanum.put("D", rs.getString("notes"));
  93. datanum.put("E", rs.getString("loc_long"));
  94. datanum.put("F", rs.getString("loc_lat"));
  95. datanum.put("G", rs.getString("start_long"));
  96. datanum.put("H", rs.getString("start_lat"));
  97. datanum.put("I", rs.getString("stop_long"));
  98. datanum.put("J", rs.getString("stop_lat"));
  99. data.add(datanum);
  100. loc_long = Double.parseDouble(datanum.get("E"));
  101. loc_lat = Double.parseDouble(datanum.get("F"));
  102.  
  103. }
  104. } catch (SQLException e){
  105. Toast.makeText(MapsActivity.this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
  106. }
  107. }
  108.  
  109.  
  110. /**
  111. * Manipulates the map once available.
  112. * This callback is triggered when the map is ready to be used.
  113. * This is where we can add markers or lines, add listeners or move the camera. In this case,
  114. * we just add a marker near Sydney, Australia.
  115. * If Google Play services is not installed on the device, the user will be prompted to install
  116. * it inside the SupportMapFragment. This method will only be triggered once the user has
  117. * installed Google Play services and returned to the app.
  118. */
  119. @Override
  120. public void onMapReady(GoogleMap googleMap) {
  121.  
  122. mMap = googleMap;
  123.  
  124. // Add a marker in Sydney and move the camera
  125. LatLng sydney = new LatLng(-34, 151);
  126. mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  127. mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  128.  
  129. LatLng loc = new LatLng(loc_long,loc_lat);
  130. mMap.addMarker(new MarkerOptions().position(loc).title("Fuck that shit"));
  131.  
  132.  
  133. }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement