예제 #1
0
  /**
   * 中心点的数据处理
   *
   * @param point
   */
  private void getAddress(LatLng point) {
    // 0. 设置中心位置
    aMap.moveCamera(CameraUpdateFactory.changeLatLng(point));
    aMap.moveCamera(
        CameraUpdateFactory.zoomTo(Integer.valueOf(getString(R.string.default_me_zoomlevel))));

    // 1. 清楚地图上的marker
    aMap.clear();

    // 2. 将地理坐标转换为中文地址
    mainMarkerLatLng = point;
    LatLonPoint latLonPoint = new LatLonPoint(point.latitude, point.longitude);
    GeocodeSearch geocoderSearch = new GeocodeSearch(this);
    geocoderSearch.setOnGeocodeSearchListener(this);
    // latLonPoint参数表示一个Latlng,第二参数表示范围多少米,GeocodeSearch.AMAP表示是国测局坐标系还是GPS原生坐标系
    RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 100, GeocodeSearch.AMAP);
    geocoderSearch.getFromLocationAsyn(query); // 设置同步逆地理编码请求

    // 3. 将坐标发送给服务器, 请求附近的停车场的坐标与停车场的信息
    // 初始化url
    String databaseUrl = null;
    databaseUrl = ParkingHttp.AddUrlType(databaseUrl, ParkingHttp.JSON_BASE_DATA);
    databaseUrl =
        ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_LAT, String.valueOf(point.latitude));
    databaseUrl =
        ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_LNG, String.valueOf(point.longitude));
    databaseUrl = ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_RANGE, RANGE_1000);
    Log.e(TAG, databaseUrl);

    if (downloadTask != null) Log.e(TAG, String.valueOf(downloadTask.cancel(true)));
    downloadTask = new DownloadTask();
    downloadTask.execute(databaseUrl);
    // 4. 将这些信息绘制在地图上
  }
예제 #2
0
 public void startDownload() {
   String strUrl = "http://www.google.com";
   String imgUrl =
       "http://icons.iconarchive.com/icons/position-relative/social-1/128/google-icon.png";
   DownloadTask dt = new DownloadTask(this);
   dt.execute(imgUrl); // strUrl
 }
  protected void addRouteOnMap(double fromLat, double fromLon, double toLat, double toLon) {

    progressdialog = ProgressDialog.show(NewOrdersRouteOptimizationMapActivity.this, null, null);
    progressdialog.setContentView(R.layout.loader);

    Log.i("", "kkk addRoute from" + fromLat + "," + fromLon);
    Log.i("", "kkk addRoute to" + toLat + "," + toLon);

    String directionUrl =
        String.format(
            "http://maps.googleapis.com/maps/api/directions/json?origin=%s,%s&destination=%s,%s&sensor=false&mode=driving",
            String.valueOf(fromLat),
            String.valueOf(fromLon),
            String.valueOf(toLat),
            String.valueOf(toLon));

    Log.i("", "kkk addRoute direction url" + directionUrl);

    DownloadTask downloadTask = new DownloadTask(mRouteHandler);

    // Start downloading json data from Google Directions API
    downloadTask.execute(directionUrl);

    // new
    // GetNoOfRoutesAPIResponseHandler(String.format("http://maps.googleapis.com/maps/api/directions/json?origin=%s,%s&destination=%s,%s&sensor=false&mode=driving",String.valueOf(fromLat),String.valueOf(fromLon),String.valueOf(toLat),String.valueOf(toLon)), mRouteHandler).start();

  }
예제 #4
0
 public void startDownload(Album album) {
   buttonParse.setEnabled(false);
   urlField.setEnabled(true);
   progressBar.setIndeterminate(false);
   progressBar.setString("");
   progressBar.setStringPainted(true);
   downloadTask = new DownloadTask(this, album);
   downloadTask.addPropertyChangeListener(this);
   downloadTask.execute();
 }
예제 #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.upgrade_progress_update);
    mInfo = (VersionInfo) getIntent().getSerializableExtra("versionInfo");
    if (mInfo == null) {
      getNewVersionInfo();
    }
    if (mInfo == null) return;
    initApkFile();
    setupView();

    downloadTask = new DownloadTask();
    downloadTask.execute(mInfo.updateURL);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // URL to the JSON data
    String strUrl =
        "https://spreadsheets.google.com/feeds/list/0AjImsUF0T00udEU4NWZhVkdnY294REVuMzRPUGxoQ1E/od6/public/values?alt=json";
    // Creating a new non-ui thread task to download json data
    DownloadTask downloadTask = new DownloadTask();
    // Starting the download process
    downloadTask.execute(strUrl);

    // storing string resources into Array
    // final String[] posts = getResources().getStringArray(R.array.posts);

    // Binding resources Array to ListAdapter
    // this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, posts));

    lv = getListView();
    @SuppressWarnings("unused")
    int x = 5;

    // Getting a reference to ListView of activity_main
    // lv = (ListView) findViewById(R.id.lv_posts);

    // listening to single list item on click

    lv.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // selected item
            HashMap<String, Object> post = mPostsList.get(position);
            String loc = post.get("location").toString();
            Log.i("SLN", loc);

            // Launching new Activity on selecting single List Item
            Intent i = new Intent(getApplicationContext(), SingleListItem.class);
            // sending data to new activity
            i.putExtra("location", loc);
            startActivity(i);
          }
        });
  }
예제 #7
0
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case DOWNLOAD_COMPLETE:
              Place_Latln_Get = true;
              Log.d("TAG", "place_latlng_get");
              Log.d("TAG", "count=" + String.valueOf(ret_place_Name.size()));
              end.setText("終點: " + ret_place_Name.get(ret_place_Name.size() - 1));
              XY =
                  new LatLng(
                      Double.parseDouble(ret_place_Y.get(0)),
                      Double.parseDouble(ret_place_X.get(0)));
              Log.d("TAG", "destination mark");

              break;
            case LOCATION_GET:
              Location_Get = true;
              Log.d("TAG", "location_get");
              break;
            default:
              break;
          }
          if (Place_Latln_Get && Location_Get) {
            if (lat != null && lng != null) {
              Log.d("TAG", "handler");
              mode = "mode=driving";
              url = getDirectionsUrl(mode);
              DownloadTask downloadTask = new DownloadTask();
              downloadTask.execute(url);
              ArrayList<LatLng> center =
                  compareLatLng(
                      ret_place_Y.get(0),
                      ret_place_X.get(0),
                      String.valueOf(lat),
                      String.valueOf(lng));
              LatLngBounds bounds = new LatLngBounds(center.get(1), center.get(0));
              map.moveCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 8));
            }
          }
        }
예제 #8
0
  // region Map Path & Marker Setups
  private void initMap() {
    // Getting reference to SupportMapFragment of the activity_main
    SupportMapFragment fm =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    // Getting Map for the SupportMapFragment
    map = fm.getMap();

    // Enable MyLocation Button in the Map
    map.setMyLocationEnabled(true);

    // Draws Start and Stop markers on the Google Map
    drawStartEndMarkers();

    // Checks, whether start and end locations are captured
    if (markerPoints.size() >= 2) {
      LatLng origin = markerPoints.get(0);
      LatLng dest = markerPoints.get(1);

      // Getting URL to the Google Directions API
      String url = getDirectionsUrl(origin, dest);

      DownloadTask downloadTask = new DownloadTask();

      // Start downloading json data from Google Directions API
      downloadTask.execute(url);

      // move Map Camera
      map.moveCamera(
          CameraUpdateFactory.newLatLngZoom(
              new LatLngBounds(markerPoints.get(0), markerPoints.get(1)).getCenter(), 10));
      // map.animateCamera(cameraUpdate);
      // locationManager.removeUpdates(this);
    } else if (markerPoints.size() == 1) {
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(markerPoints.get(0), 15));
    }
  }
예제 #9
0
  /**
   * 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;
    // mMap.setMyLocationEnabled(true);
    mMap.setBuildingsEnabled(true);
    mMap.setTrafficEnabled(true);

    UiSettings gmapsettings = mMap.getUiSettings();
    gmapsettings.setMyLocationButtonEnabled(true);
    gmapsettings.setCompassEnabled(true);
    gmapsettings.setZoomControlsEnabled(true);
    gmapsettings.setZoomControlsEnabled(true);
    gmapsettings.setScrollGesturesEnabled(true);
    gmapsettings.setRotateGesturesEnabled(true);

    Intent ri = getIntent();
    Bundle a = ri.getExtras();
    String start = a.getString("start");
    String end = a.getString("end");

    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses = null;
    try {
      addresses = geocoder.getFromLocationName(start, 1);
    } catch (IOException e) {
      e.printStackTrace();
    }

    double slatitude = addresses.get(0).getLatitude();
    double slongitude = addresses.get(0).getLongitude();

    // Add a marker to start
    LatLng smarker = new LatLng(slatitude, slongitude);
    mMap.addMarker(
        new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.markers1))
            .position(smarker)
            .title("Pick Up"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(smarker));

    try {
      addresses = geocoder.getFromLocationName(end, 1);
    } catch (IOException e) {
      e.printStackTrace();
    }

    double elatitude = addresses.get(0).getLatitude();
    double elongitude = addresses.get(0).getLongitude();

    // Add a marker to end
    LatLng emarker = new LatLng(elatitude, elongitude);
    mMap.addMarker(
        new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.markers2))
            .position(emarker)
            .title("Destination"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(emarker));

    LatLng origin = smarker;
    LatLng dest = emarker;

    // Getting URL to the Google Directions API
    String url = getDirectionsUrl(origin, dest);

    DownloadTask downloadTask = new DownloadTask();

    // Start downloading json data from Google Directions API
    downloadTask.execute(url);

    mMap.animateCamera(CameraUpdateFactory.newLatLng(smarker));
  }
예제 #10
0
 private void downloadUpdate(String url, CallbackContext callbackContext) {
   final DownloadTask downloadTask = new DownloadTask(this.myContext, callbackContext);
   downloadTask.execute(url);
 }
예제 #11
0
  public void reloadSubreddits(final ISubredditChangedListener subredditChangedListener) {
    DownloadTask downloadTask =
        new DownloadTask(sessionManager) {
          @Override
          protected void onDownloadComplete(List<RedditPost> results) {
            LogMe.e("Downloaded " + results.size() + " subreddit categories");

            subredditList.clear();
            subredditList.add(DEFAULT_SUBREDDIT);
            for (RedditPost redditPost : results) {
              String subredditUrl = redditPost.getUrl().toString();
              if (subredditUrl.startsWith(SUBREDDIT_PREFIX)) {
                subredditUrl = subredditUrl.substring(3);
              }
              subredditList.add(subredditUrl);
            }

            progressBar.setVisibility(View.INVISIBLE);

            subredditSpinnerView.setOnItemSelectedListener(
                new OnItemSelectedListener() {
                  public void onItemSelected(
                      AdapterView<?> parent, View view, int position, long id) {
                    String subredditName = subredditList.get(position);
                    changeSubreddit(subredditChangedListener, subredditName);
                  }

                  public void onNothingSelected(AdapterView<?> parent) {
                    subredditSpinnerView.setSelection(0);
                  }
                });

            subredditSpinnerView.setOnLongClickListener(
                new OnLongClickListener() {
                  public boolean onLongClick(View view) {
                    final EditText editText = new EditText(SubredditController.this.activity);

                    new AlertDialog.Builder(SubredditController.this.activity)
                        //
                        .setTitle("Enter subreddit")
                        .setView(editText)
                        .setPositiveButton(
                            "Ok",
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                String newSubreddit = editText.getText().toString();
                                addNewSubreddit(subredditChangedListener, newSubreddit);
                              }
                            })
                        .setNegativeButton(
                            "Cancel",
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                // Do nothing.
                              }
                            })
                        .show();

                    return true;
                  }
                });

            subredditSpinnerView.setAdapter(createNewSubredditAdapter());
            subredditSpinnerView.setSelection(0);
          }
        };

    String subredditUrl = dataSourceUrl + REDDITS_URL;
    LogMe.e("Subreddits from: " + subredditUrl);
    downloadTask.execute(subredditUrl);
  }
예제 #12
0
  @Override
  public void onConnected(Bundle bundle) {
    Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (l != null) {
      mCurrentLatLn = new LatLng(l.getLatitude(), l.getLongitude());
      UIUtils.moveCameraTo(mGoogleMap, mCurrentLatLn, this);
    }

    if (mCurrentLatLn != null) {
      final Parish mostClosed = CoreUtils.getMinLatLng(mCurrentLatLn);

      if (mostClosed != null) {
        // Creating MarkerOptions
        MarkerOptions options = new MarkerOptions();

        // Setting the position of the marker
        options.position(mostClosed.getLatLng());
        options.snippet(mostClosed.getDisplayName());
        options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
        mGoogleMap.addMarker(options);

        // Getting URL to the Google Directions API
        String url = getDirectionsUrl(mCurrentLatLn, mostClosed.getLatLng());

        DownloadTask downloadTask = new DownloadTask();

        // Start downloading json data from Google Directions API
        downloadTask.execute(url);
      }
      progressDialog.dismiss();
      showGroup(mCurrentLatLn, mostClosed.getLatLng());

      btnDraw.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              String uri =
                  String.format(
                      Locale.ENGLISH,
                      "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)",
                      mCurrentLatLn.latitude,
                      mCurrentLatLn.longitude,
                      "My position",
                      mostClosed.getLatLng().latitude,
                      mostClosed.getLatLng().longitude,
                      "" + mostClosed.getDisplayName());
              Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
              intent.setClassName(
                  "com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
              startActivity(intent);
            }
          });
      //            btnDraw.setVisibility(View.VISIBLE);

    } else {
      progressDialog.dismiss();
      Toast.makeText(GoActivity.this, "Please enable your location service.", Toast.LENGTH_SHORT)
          .show();
    }
  }
예제 #13
0
  /** function to load map. If map is not created it will create it for you */
  private void initilizeMap() {
    if (googleMap == null) {
      try {
        prefs = getSharedPreferences("Zira", MODE_PRIVATE);
        curLatitude = Double.parseDouble(prefs.getString("tripstarttlat", ""));
        curLongitude = Double.parseDouble(prefs.getString("tripstartlong", ""));
        destLongitude = Double.parseDouble(prefs.getString("tripdestlong", ""));
        destLatitude = Double.parseDouble(prefs.getString("tripdestlat", ""));
      } catch (Exception e) {
        e.printStackTrace();
      }
      googleMap =
          ((MapFragment) getFragmentManager().findFragmentById(R.id.rider_ride_map)).getMap();
      googleMap.setMyLocationEnabled(true);
      googleMap.getUiSettings().setRotateGesturesEnabled(true);
      googleMap.getUiSettings().setZoomControlsEnabled(false);
      CameraPosition cameraPosition =
          new CameraPosition.Builder()
              .target(new LatLng(curLatitude, curLongitude))
              .zoom(15)
              .build();

      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

      placeMarker();

      LatLng curLatLng = new LatLng(curLatitude, curLongitude);
      LatLng destLatLng = new LatLng(destLatitude, destLongitude);

      Log.i("tag", "Longitude:" + curLongitude);
      Log.i("tag", "Latitude:" + curLongitude);
      Log.i("tag", "destLongitude:" + destLongitude);
      Log.i("tag", "destLatitude:" + destLatitude);

      String url = getDirectionsUrl(curLatLng, destLatLng);
      DownloadTask downloadTask = new DownloadTask();
      downloadTask.execute(url);

      // check if map is created successfully or not
      if (googleMap == null) {
        Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT)
            .show();
      }
      locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
      criteria = new Criteria();

      // Getting the name of the best provider
      provider = locationManager.getBestProvider(criteria, true);

      try {
        boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean enabledWiFi = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        // Check if enabled and if not send user to the GSP settings
        if (!enabledGPS && !enabledWiFi) {
          Toast.makeText(EndRideActivity.this, "GPS signal not found", Toast.LENGTH_LONG).show();
          Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
          startActivity(intent);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      locationManager.requestLocationUpdates(provider, 15000, 0, this);
    }
  }
예제 #14
0
 public void download(String url, String fileName, String title, String text) {
   DownloadTask downloadTask = new DownloadTask(title, text);
   downloadTask.execute(url, fileName);
 }