显示标记而不跳跃在屏幕上

时间:2016-04-05 07:49:15

标签: android performance android-layout android-fragments

我想显示标记而不在屏幕上跳跃,即当移动标记并在屏幕上绘图时,它会像标记跳转到下一个位置。

我想顺利移动标记。

这是我的代码:

  @Override
public void onConnected(Bundle bundle) {
    Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();

    mListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            latitude = location.getLatitude();
            longitude = location.getLongitude();
            LatLng latLng1 = new LatLng(latitude, longitude);
            // mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            Toast.makeText(MainActivity.this, "Location : " + location.getLatitude() + ", " + location.getLongitude(), Toast.LENGTH_LONG).show();
            if (i == 0) {
                gotoLocation(location.getLatitude(), location.getLongitude(), 15);

                i = 1;

            }
            AppUtill.UniqueId();
            new JSONAsyncTask().execute("http://10.5.8/hajjapi/api/GPSLocator/GetLocations");

            if (AppStatus.getInstance(getContext()).isOnline()) {
                //    new JSONAsyncTaskDistance().execute("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=31.5003567,74.3226214&destinations=31.4821587%2C74.3104778&key=AIzaSyA4j7PYgp9oP5wVclG0IDtYhowNzJr871M");

            } else {

                Toast.makeText(MainActivity.this, "Turn On your WIFI ", Toast.LENGTH_LONG).show();

            }

         /*   if (marker != null) {
                marker.remove();

            }*/


        }
    };
    LocationRequest request = LocationRequest.create();
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    request.setInterval(1000);
    request.setFastestInterval(1000);
    LocationServices.FusedLocationApi.requestLocationUpdates(mLocationClient, request, mListener);
}

OnPost执行:我从服务器收到时,每隔一秒在屏幕上绘制标记。

   protected void onPostExecute(Boolean result) {
        // dialog.cancel();
        // adapter.notifyDataSetChanged();
        Toast.makeText(getApplicationContext(), "Receicve data from server", Toast.LENGTH_LONG).show();

        if (result == false) {
            Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
        }
        try {
            //ArrayList list = new ArrayList<>();
            //TODO: remove previus markers
            if (marker != null) {
                mMap.clear();
                Toast.makeText(getApplicationContext(), "Remove", Toast.LENGTH_LONG).show();

            }
            for (LatLng object : latLngList)

                marker = mMap.addMarker(new MarkerOptions().title("User Name").position(object).icon(BitmapDescriptorFactory.fromResource(R.drawable.female4)));

            System.out.println(marker.getPosition()+"  Marker position.......");
        } catch (Exception e) {
            Toast.makeText(MainActivity.this, "Error ", Toast.LENGTH_LONG).show();
            // mMap.clear();
        }

    }

1 个答案:

答案 0 :(得分:1)

查看Maphacks-Animating Markers的官方视频。你也可以在这个Github上找到源代码link