Advertisement
Meskiusa

Untitled

Mar 26th, 2019
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. package i12.kvk.appr;
  2.  
  3. import android.os.AsyncTask;
  4. import android.os.Build;
  5. import android.support.annotation.RequiresApi;
  6. import android.util.Log;
  7.  
  8. import com.google.android.gms.maps.CameraUpdateFactory;
  9. import com.google.android.gms.maps.GoogleMap;
  10. import com.google.android.gms.maps.model.LatLng;
  11. import com.google.android.gms.maps.model.Marker;
  12. import com.google.android.gms.maps.model.MarkerOptions;
  13.  
  14. import java.io.BufferedReader;
  15. import java.io.InputStreamReader;
  16. import java.net.HttpURLConnection;
  17. import java.net.URL;
  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.List;
  21. import java.util.TimerTask;
  22.  
  23. public class GetUrlContentTask extends AsyncTask<String, Integer, String> {
  24. private static List<Marker> markers = new ArrayList<>();
  25. static GoogleMap map;
  26.  
  27.  
  28. protected String doInBackground(String... urls) {
  29. try {
  30. URL url = new URL(urls[0]);
  31. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  32. connection.setRequestMethod("GET");
  33. connection.setDoOutput(true);
  34. connection.setConnectTimeout(50000);
  35. connection.setReadTimeout(50000);
  36. connection.connect();
  37. BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  38. String content = "", line;
  39. while ((line = rd.readLine()) != null) {
  40. content += line + "\n";
  41. }
  42. return content;
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. }
  46. return null;
  47. }
  48.  
  49. protected void onProgressUpdate(Integer... progress) {
  50. }
  51.  
  52. @RequiresApi(api = Build.VERSION_CODES.N)
  53. protected void onPostExecute(String result) {
  54. // this is executed on the main thread after the process is over
  55. // update your UI here
  56. // displayMessage(result);
  57. String tst = "2,31,21091530,55863788,79,162,JZO 639 wm,";
  58. tst = tst.replaceFirst(".$", "");
  59. List<JsonParseEntity> jsonParseEntityList = new ArrayList<>();
  60. assert result != null;
  61. Log.d("Crap", result);
  62. List<String> stringList = new ArrayList<>(Arrays.asList(result.split("\n")));
  63.  
  64. for (String n : stringList) {
  65.  
  66. List<String> strings = new ArrayList<>(Arrays.asList(n.split(",")));
  67. jsonParseEntityList.add(new JsonParseEntity(strings.get(1),
  68. Double.valueOf(strings.get(2).substring(0, 2) + "." + strings.get(2).substring(2)),
  69. Double.valueOf(strings.get(3).substring(0, 2) + "." + strings.get(3).substring(2))
  70. ));
  71. }
  72.  
  73.  
  74. map = MapsActivity.mMap;
  75. if (map == null) {
  76. map = MapsActivityAdmin.mMap;
  77. }
  78. for (JsonParseEntity js: jsonParseEntityList.subList(0, jsonParseEntityList.size()/4)) {
  79. Marker marker = map.addMarker(new MarkerOptions().position(new LatLng(js.lat,js.lon)));
  80. markers.add(marker);
  81. }
  82. // LatLng latLng = new LatLng(jsonParseEntityList.get(4).lat, jsonParseEntityList.get(4).lon);
  83. // map.addMarker(new MarkerOptions().position(latLng));
  84.  
  85. // Add a marker in Sydney, Australia, and move the camera.
  86. // LatLng sydney = new LatLng(-34, 151);
  87. // mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  88. // mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  89.  
  90. }
  91.  
  92. public static List<Marker> getMarkers() {
  93. return markers;
  94. }
  95. @RequiresApi(api = Build.VERSION_CODES.N)
  96. public static void cleanMap(){
  97. markers.forEach(Marker::remove);
  98. // map.clear();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement