random Location - Android Map

Android examples for Map:Location

Description

random Location

Demo Code


import java.io.Serializable;
import java.util.Random;

public class Main{
    public static Location ramdomLocation() {
        final Random random = new Random();
        final double latitude = random.nextDouble();
        final double longitude = random.nextDouble();
        final double altitude = random.nextDouble();
        final long accurancy = random.nextInt();
        final long time = System.nanoTime();

        return new Location() {

            @Override// ww  w  .j a v  a2 s .com
            public void setAccuracy(long accuracy) {

            }

            @Override
            public Double getLatitude() {
                return latitude;
            }

            @Override
            public Double getLongitude() {
                return longitude;
            }

            @Override
            public Double getAltitude() {
                return altitude;
            }

            @Override
            public long getAccuracy() {
                return accurancy;
            }

            @Override
            public void setLatitude(Double latitude) {

            }

            @Override
            public void setLongitude(Double longitude) {

            }

            @Override
            public Double getAltitudeAccuracy() {
                return null;
            }

            @Override
            public Long getTime() {
                return time;
            }

            @Override
            public LocationSource getSource() {
                return LocationSource.GPS;
            }
        };
    }
}

Related Tutorials