com.google.android.gms.maps.model.LatLng Java Examples

The following examples show how to use com.google.android.gms.maps.model.LatLng. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetNearbyPlacesData.java    From Krishi-Seva with MIT License 6 votes vote down vote up
private void ShowNearbyPlaces(List<HashMap<String, String>> nearbyPlacesList) {
    for (int i = 0; i < nearbyPlacesList.size(); i++) {
        Log.d("onPostExecute","Entered into showing locations");
        MarkerOptions markerOptions = new MarkerOptions();
        HashMap<String, String> googlePlace = nearbyPlacesList.get(i);
        double lat = Double.parseDouble(googlePlace.get("lat"));
        double lng = Double.parseDouble(googlePlace.get("lng"));
        String placeName = googlePlace.get("place_name");
        String vicinity = googlePlace.get("vicinity");
        LatLng latLng = new LatLng(lat, lng);
        markerOptions.position(latLng);
        markerOptions.title(placeName + " : " + vicinity);
        mMap.addMarker(markerOptions);
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
    }
}
 
Example #2
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
private int whichMapQ(double lat, double lon) {
	LatLng center = mMap.getCameraPosition().target;
	double mapCenterLat = center.latitude;
	double mapCenterLon = center.longitude;
	
	if( (lat < mapCenterLat) && (lon < mapCenterLon)) {
		return 1;
	} else if( (lat > mapCenterLat) && (lon < mapCenterLon)) {
		return 2;
	} else if( (lat > mapCenterLat) && (lon > mapCenterLon)) {
		return 3;
	} else if( (lat < mapCenterLat) && (lon > mapCenterLon)) {
		return 4;
	} else {
		return 0;	
	}
}
 
Example #3
Source File: MovingMarkerActivity.java    From Airbnb-Android-Google-Map-View with MIT License 6 votes vote down vote up
public void initialize(boolean showPolyLine) {
    reset();
    this.showPolyline = showPolyLine;

    highLightMarker(0);

    if (showPolyLine) {
        polyLine = initializePolyLine();
    }

    // We first need to put the camera in the correct position for the first run (we need 2 markers for this).....
    LatLng markerPos = markers.get(0).getPosition();
    LatLng secondPos = markers.get(1).getPosition();

    setupCameraPositionForMovement(markerPos, secondPos);

}
 
Example #4
Source File: AttractionListFragment.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private static List<Attraction> loadAttractionsFromLocation(final LatLng curLatLng) {
    String closestCity = TouristAttractions.getClosestCity(curLatLng);
    if (closestCity != null) {
        List<Attraction> attractions = ATTRACTIONS.get(closestCity);
        if (curLatLng != null) {
            Collections.sort(attractions,
                    new Comparator<Attraction>() {
                        @Override
                        public int compare(Attraction lhs, Attraction rhs) {
                            double lhsDistance = SphericalUtil.computeDistanceBetween(
                                    lhs.location, curLatLng);
                            double rhsDistance = SphericalUtil.computeDistanceBetween(
                                    rhs.location, curLatLng);
                            return (int) (lhsDistance - rhsDistance);
                        }
                    }
            );
        }
        return attractions;
    }
    return null;
}
 
Example #5
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public Marker addPointMarkerByHistory(MapPointLatLng mpl) {
    BitmapDescriptor mBitmapDescriptor;
    float anchorY;
    if (this.lineMarkerSelectListener.getOration() != 0) {
        mBitmapDescriptor = this.gdCustemMarkerView.createMapPointAngleNoPioView(this.context, R.drawable.x8_ai_line_point_with_angle1, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, false);
        anchorY = 0.64285713f;
    } else if (mpl.mInrertestPoint != null) {
        mpl.setAngle(getPointAngle(mpl, mpl.mInrertestPoint));
        mBitmapDescriptor = this.gdCustemMarkerView.createMapPointAngleNoPioView(this.context, R.drawable.x8_ai_line_point_with_angle1, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, false);
        anchorY = 0.64285713f;
    } else {
        mBitmapDescriptor = this.gdCustemMarkerView.createMapPointNoAngleNoPioView(this.context, R.drawable.x8_ai_line_point_no_angle1, mpl.altitude, mpl.nPos, mpl.isSelect, false);
        anchorY = 0.64285713f;
    }
    Marker marker = this.googleMap.addMarker(new MarkerOptions().position(new LatLng(mpl.latitude, mpl.longitude)).icon(mBitmapDescriptor).anchor(0.5f, anchorY).draggable(false));
    marker.setFlat(true);
    return marker;
}
 
Example #6
Source File: UtilityService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    String action = intent != null ? intent.getAction() : null;
    if (ACTION_ADD_GEOFENCES.equals(action)) {
        addGeofencesInternal();
    } else if (ACTION_GEOFENCE_TRIGGERED.equals(action)) {
        geofenceTriggered(intent);
    } else if (ACTION_REQUEST_LOCATION.equals(action)) {
        requestLocationInternal();
    } else if (ACTION_LOCATION_UPDATED.equals(action)) {
        locationUpdated(intent);
    } else if (ACTION_CLEAR_NOTIFICATION.equals(action)) {
        clearNotificationInternal();
    } else if (ACTION_CLEAR_REMOTE_NOTIFICATIONS.equals(action)) {
        clearRemoteNotifications();
    } else if (ACTION_FAKE_UPDATE.equals(action)) {
        LatLng currentLocation = Utils.getLocation(this);

        // If location unknown use test city, otherwise use closest city
        String city = currentLocation == null ? TouristAttractions.TEST_CITY :
                TouristAttractions.getClosestCity(currentLocation);

        showNotification(city,
                intent.getBooleanExtra(EXTRA_TEST_MICROAPP, Constants.USE_MICRO_APP));
    }
}
 
Example #7
Source File: MapsActivity.java    From Krishi-Seva with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    String lat= getIntent().getStringExtra("lat");
    String longg= getIntent().getStringExtra("long");
    latitude= Double.parseDouble(lat);
    longitude= Double.parseDouble(longg);
    kochi = new LatLng(latitude, longitude);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkLocationPermission();
    }

    if (!CheckGooglePlayServices()) {
        Log.d("onCreate", "Finishing test case since Google Play Services are not available");
        finish();
    }
    else {
        Log.d("onCreate","Google Play Services available.");
    }

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example #8
Source File: Maps.java    From aware with MIT License 6 votes vote down vote up
/**
 * Sets marker at given location on map
 *
 * @param LocationLat  latitude
 * @param LocationLong longitude
 * @param LocationName name of location
 * @param LocationIcon icon
 */
public void ShowMarker(Double LocationLat, Double LocationLong, String LocationName, Integer LocationIcon) {
    LatLng Coord = new LatLng(LocationLat, LocationLong);

    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        if (map != null) {
            map.setMyLocationEnabled(true);
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(Coord, 10));

            MarkerOptions abc = new MarkerOptions();
            MarkerOptions x = abc
                    .title(LocationName)
                    .position(Coord)
                    .icon(BitmapDescriptorFactory.fromResource(LocationIcon));
            map.addMarker(x);

        }
    }
}
 
Example #9
Source File: SphericalUtil.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the length of the given path, in meters, on Earth.
 */
public static double computeLength(List<LatLng> path) {
    if (path.size() < 2) {
        return 0;
    }
    double length = 0;
    LatLng prev = path.get(0);
    double prevLat = toRadians(prev.latitude);
    double prevLng = toRadians(prev.longitude);
    for (LatLng point : path) {
        double lat = toRadians(point.latitude);
        double lng = toRadians(point.longitude);
        length += distanceRadians(prevLat, prevLng, lat, lng);
        prevLat = lat;
        prevLng = lng;
    }
    return length * EARTH_RADIUS;
}
 
Example #10
Source File: DirectionsJSONParser.java    From Self-Driving-Car with MIT License 5 votes vote down vote up
/**
 * Method to decode polyline points
 * Courtesy : http://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java
 * */
private List decodePoly(String encoded) {



    List poly = new ArrayList();
    int index = 0, len = encoded.length();
    int lat = 0, lng = 0;

    while (index < len) {
        int b, shift = 0, result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lat += dlat;

        shift = 0;
        result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lng += dlng;

        LatLng p = new LatLng((((double) lat / 1E5)),
                (((double) lng / 1E5)));
        poly.add(p);
        Log.e("CallNumber", String.valueOf(i));
        Log.e("Encoded", String.valueOf(p));
    }
    i++;
    return poly;
}
 
Example #11
Source File: GglMap.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public double[] getManLatLng() {
    double[] latLng = new double[2];
    if (this.gglMapLocationManager == null) {
        return null;
    }
    LatLng ll = this.gglMapLocationManager.getManLocation();
    if (ll == null) {
        return null;
    }
    latLng[0] = ll.latitude;
    latLng[1] = ll.longitude;
    return latLng;
}
 
Example #12
Source File: FeatureOverlayQuery.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Perform a query based upon the map click location and build a info message
 *
 * @param latLng      location
 * @param zoom        current zoom level
 * @param boundingBox click bounding box
 * @param tolerance   tolerance distance
 * @param projection  desired geometry projection
 * @return information message on what was clicked, or null
 */
private String buildMapClickMessage(LatLng latLng, double zoom, BoundingBox boundingBox, double tolerance, Projection projection) {
    String message = null;

    // Verify the features are indexed and we are getting information
    if (isIndexed() && (maxFeaturesInfo || featuresInfo)) {

        if (isOnAtCurrentZoom(zoom, latLng)) {

            // Get the number of features in the tile location
            long tileFeatureCount = tileFeatureCount(latLng, zoom);

            // If more than a configured max features to draw
            if (isMoreThanMaxFeatures(tileFeatureCount)) {

                // Build the max features message
                if (maxFeaturesInfo) {
                    message = buildMaxFeaturesInfoMessage(tileFeatureCount);
                }

            }
            // Else, query for the features near the click
            else if (featuresInfo) {

                // Query for results and build the message
                FeatureIndexResults results = queryFeatures(boundingBox, projection);
                message = featureInfoBuilder.buildResultsInfoMessageAndClose(results, tolerance, latLng, projection);

            }

        }
    }

    return message;
}
 
Example #13
Source File: GalleryTest.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
@Before
public void alloc() {
    mTitle = "Title";
    mDescription = "Description";
    mGalleryId = "galleryId";
    mPosition = new LatLng(51.5014, -0.1419);
    mGalleryUnderTest = new Gallery(mTitle, mDescription, mGalleryId, mPosition);
}
 
Example #14
Source File: MapPresenter.java    From ridesharing-android with MIT License 5 votes vote down vote up
public void animateCamera(final LatLng latLng) {
    if (googleMap != null) {
        googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
            @Override
            public void onMapLoaded() {
                googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                        latLng,
                        17
                ));
            }
        });
    }
}
 
Example #15
Source File: Home.java    From UberClone with MIT License 5 votes vote down vote up
private void implementDestinationRecyclerView(final ArrayList<Results> results) {
    PlacesAdapter placesAdapter=new PlacesAdapter(this, results, new ClickListener() {
        @Override
        public void onClick(View view, int index) {
            mPlaceDestination=results.get(index).formatted_address;
            etFinalDestination.setText(mPlaceDestination);

            llPickupInput.setVisibility(View.GONE);
            llPickupPlace.setVisibility(View.VISIBLE);
            llDestinationInput.setVisibility(View.GONE);
            llDestinationPlace.setVisibility(View.VISIBLE);

            Double lat=Double.valueOf(results.get(index).geometry.location.lat);
            Double lng=Double.valueOf(results.get(index).geometry.location.lng);
            LatLng latLng=new LatLng(lat, lng);
            if(destinationMarker!=null)
                destinationMarker.remove();
            destinationMarker=mMap.addMarker(new MarkerOptions().position(latLng)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_destination_marker))
                    .title("Destination"));
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f));

            BottomSheetRiderFragment mBottomSheet=BottomSheetRiderFragment.newInstance(mPlaceLocation, mPlaceDestination, false);
            mBottomSheet.show(getSupportFragmentManager(), mBottomSheet.getTag());
        }
    });
    rvDestinationPlaces.setAdapter(placesAdapter);
}
 
Example #16
Source File: FragMap.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(@NonNull Location location) {
    mLocation = location;
    if (!isAdded() || isDetached() || mMap == null)
        return;
    LatLng pos = new LatLng(location.getLatitude(), location.getLongitude());
    if (mLine != null) {
        ArrayList<LatLng> points = new ArrayList<>();
        points.add(pos);
        points.add(mKaabePos);
        mLine.setPoints(points);
        mMarker.setPosition(pos);
        mCircle.setCenter(pos);
        mCircle.setRadius(location.getAccuracy());
        mMap.animateCamera(CameraUpdateFactory.newLatLng(pos));
    } else {
        //zoom first time
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 15));


        mLine = mMap.addPolyline(
                new PolylineOptions().add(pos).add(mKaabePos).geodesic(true).color(Color.parseColor("#3bb2d0")).width(3).zIndex(1));

        mMarker = mMap.addMarker(
                new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_mylocation)).anchor(0.5f, 0.5f).position(pos)
                        .zIndex(2));

        mCircle = mMap.addCircle(
                new CircleOptions().center(pos).fillColor(0xAA4FC3F7).strokeColor(getResources().getColor(R.color.colorPrimary)).strokeWidth(2)
                        .radius(mLocation.getAccuracy()));
    }


}
 
Example #17
Source File: GeocoderTask.java    From MapsMeasure with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(final Address address) {
    if (address == null) {
        if (BuildConfig.DEBUG) Logger.log("no location found");
        Toast.makeText(map.getBaseContext(), R.string.no_location_found, Toast.LENGTH_SHORT).show();
    } else {
        map.getMap().animateCamera(CameraUpdateFactory
                .newLatLngZoom(new LatLng(address.getLatitude(), address.getLongitude()),
                        Math.max(10, map.getMap().getCameraPosition().zoom)));
    }
}
 
Example #18
Source File: SecondExampleActivity.java    From Curve-Fit with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    this.map = googleMap;
    curveManager = new CurveManager(map);

    ArrayList<LatLng> latLngArrayList = new ArrayList<>();
    latLngArrayList.add(new LatLng(12.30548451, 76.65521267));
    latLngArrayList.add(new LatLng(19.81516491, 85.83133625));
    latLngArrayList.add(new LatLng(26.9124336, 75.7872709));
    latLngArrayList.add(new LatLng(28.596111, 83.820278));

    CurveOptions curveOptions = new CurveOptions();
    curveOptions.addAll(latLngArrayList);
    curveOptions.color(Color.DKGRAY);
    curveOptions.setComputePointsBasedOnScreenPixels(false);
    curveOptions.setAlpha(0.5f);
    curveOptions.width(10);
    List<PatternItem> pattern = Arrays.asList(new Dash(30), new Gap(20));
    curveOptions.pattern(pattern);
    curveOptions.geodesic(false);

    for (LatLng position : latLngArrayList) {
        new MarkerOptions().position(position);
        map.addMarker(new MarkerOptions().position(position));
    }
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(21.146633, 79.088860), 5));

    curveManager.drawCurveAsync(curveOptions);
}
 
Example #19
Source File: AutoCompleteAdapter.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void displayPredictiveResults( String query )
{
    //Southwest corner to Northeast corner.
    LatLngBounds bounds = new LatLngBounds( new LatLng( 39.906374, -105.122337 ), new LatLng( 39.949552, -105.068779 ) );

    //Filter: https://developers.google.com/places/supported_types#table3
    List<Integer> filterTypes = new ArrayList<Integer>();
    filterTypes.add( Place.TYPE_ESTABLISHMENT );

    Places.GeoDataApi.getAutocompletePredictions( mGoogleApiClient, query, bounds, AutocompleteFilter.create( filterTypes ) )
        .setResultCallback (
            new ResultCallback<AutocompletePredictionBuffer>() {
                @Override
                public void onResult( AutocompletePredictionBuffer buffer ) {

                    if( buffer == null )
                        return;

                    if( buffer.getStatus().isSuccess() ) {
                        for( AutocompletePrediction prediction : buffer ) {
                            //Add as a new item to avoid IllegalArgumentsException when buffer is released
                            add( new AutoCompletePlace( prediction.getPlaceId(), prediction.getDescription() ) );
                        }
                    }

                    //Prevent memory leak by releasing buffer
                    buffer.release();
                }
            }, 60, TimeUnit.SECONDS );
}
 
Example #20
Source File: MyTracksMapFragment.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default LatLng.
 */
private LatLng getDefaultLatLng() {
  MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity());
  Location location = myTracksProviderUtils.getLastValidTrackPoint();
  if (location != null) {
    return new LatLng(location.getLatitude(), location.getLongitude());
  }
  return new LatLng(DEFAULT_LATITUDE, DEFAULT_LONGITUDE);
}
 
Example #21
Source File: MapFragment.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void initCamera() {
    CameraPosition position = CameraPosition.builder()
            .target( new LatLng( 40.7506, -73.9936 ) )
            .zoom( 18f )
            .bearing( 0.0f )
            .tilt( 0.0f )
            .build();

    getMap().animateCamera( CameraUpdateFactory.newCameraPosition( position ), null );
    getMap().setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
 
Example #22
Source File: MapFragment.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapLongClick(LatLng latLng) {
    MarkerOptions options = new MarkerOptions().position( latLng );
    options.title( getAddressFromLatLng(latLng) );

    options.icon( BitmapDescriptorFactory.fromBitmap(
            BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher ) ) );

    getMap().addMarker(options);
}
 
Example #23
Source File: MapActivity.java    From nongbeer-mvp-android-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady( GoogleMap googleMap ){
    map = googleMap;
    if( isLocationEnable() ){
        Location location = getLastKnownLocation();
        if( location != null ){
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            LatLng current = new LatLng( latitude, longitude );
            map.moveCamera( CameraUpdateFactory.newLatLngZoom( current, DEFAULT_ZOOM ) );
        }
    }
    setupMap();
}
 
Example #24
Source File: ShareLocationActivity.java    From ShareLocationPlugin with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
	if (this.mLastLocation == null) {
		centerOnLocation(new LatLng(location.getLatitude(), location.getLongitude()));
		this.mShareButton.setEnabled(true);
		this.mShareButton.setTextColor(0xde000000);
		this.mShareButton.setText(R.string.share);
	}
	this.mLastLocation = location;
}
 
Example #25
Source File: PolyUtil.java    From MapsMeasure with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the distance on the sphere between the point p and the line segment start to end.
 *
 * @param p     the point to be measured
 * @param start the beginning of the line segment
 * @param end   the end of the line segment
 * @return the distance in meters (assuming spherical earth)
 */
public static double distanceToLine(final LatLng p, final LatLng start, final LatLng end) {
    if (start.equals(end)) {
        computeDistanceBetween(end, p);
    }

    final double s0lat = toRadians(p.latitude);
    final double s0lng = toRadians(p.longitude);
    final double s1lat = toRadians(start.latitude);
    final double s1lng = toRadians(start.longitude);
    final double s2lat = toRadians(end.latitude);
    final double s2lng = toRadians(end.longitude);

    double s2s1lat = s2lat - s1lat;
    double s2s1lng = s2lng - s1lng;
    final double u = ((s0lat - s1lat) * s2s1lat + (s0lng - s1lng) * s2s1lng) /
            (s2s1lat * s2s1lat + s2s1lng * s2s1lng);
    if (u <= 0) {
        return computeDistanceBetween(p, start);
    }
    if (u >= 1) {
        return computeDistanceBetween(p, end);
    }
    LatLng sa = new LatLng(p.latitude - start.latitude, p.longitude - start.longitude);
    LatLng sb = new LatLng(u * (end.latitude - start.latitude),
            u * (end.longitude - start.longitude));
    return computeDistanceBetween(sa, sb);
}
 
Example #26
Source File: MapPickerActivity.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa.
 * <p/>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQ_LOCATION);
            im.actor.runtime.Log.d("Permissions", "MapPickerActivity.setUpMap - no permission :c");
            return;
        }
    }

    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    for (String provider : locationManager.getAllProviders()) {
        currentLocation = locationManager.getLastKnownLocation(provider);
        if (currentLocation != null) {
            break;
        }
    }

    if (currentLocation != null) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 14));
        fetchPlaces(null);
    }
    mMap.setOnMyLocationChangeListener(this);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);
    mMap.getUiSettings().setZoomControlsEnabled(false);
    mMap.getUiSettings().setCompassEnabled(false);
    mMap.setMyLocationEnabled(true);
    mMap.setOnMapLongClickListener(this);
    mMap.setOnMarkerClickListener(this);
}
 
Example #27
Source File: Projection.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public IGeoPoint fromPixels(final int x, final int y) {
	mPoint.x = x;
	mPoint.y = y;
	final LatLng latLng = mProjection.fromScreenLocation(mPoint);
	return new GeoPoint(latLng);
}
 
Example #28
Source File: RouteDecode.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
public static ArrayList<LatLng> decodePoly(String encoded) {
    ArrayList<LatLng> poly = new ArrayList<LatLng>();
    int index = 0, len = encoded.length();
    int lat = 0, lng = 0;
    while (index < len) {
        int b, shift = 0, result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lat += dlat;
        shift = 0;
        result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lng += dlng;

        LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
        poly.add(position);
    }
    return poly;
}
 
Example #29
Source File: LocationHolder.java    From PokeFaker with MIT License 5 votes vote down vote up
public LatLng pollLatLng() {
    if (mXPreference != null) {
        mXPreference.reload();
        mCacheLatLng = restoreFromXpreference();
    }
    return mCacheLatLng;
}
 
Example #30
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Add the list of points as markers
 *
 * @param map                 google map
 * @param points              points
 * @param customMarkerOptions custom marker options
 * @param ignoreIdenticalEnds ignore identical ends flag
 * @return list of markers
 */
public List<Marker> addPointsToMapAsMarkers(GoogleMap map,
                                            List<LatLng> points, MarkerOptions customMarkerOptions,
                                            boolean ignoreIdenticalEnds) {

    List<Marker> markers = new ArrayList<Marker>();
    for (int i = 0; i < points.size(); i++) {
        LatLng latLng = points.get(i);

        if (points.size() > 1 && i + 1 == points.size() && ignoreIdenticalEnds) {
            LatLng firstLatLng = points.get(0);
            if (latLng.latitude == firstLatLng.latitude
                    && latLng.longitude == firstLatLng.longitude) {
                break;
            }
        }

        MarkerOptions markerOptions = new MarkerOptions();
        if (customMarkerOptions != null) {
            markerOptions.icon(customMarkerOptions.getIcon());
            markerOptions.anchor(customMarkerOptions.getAnchorU(),
                    customMarkerOptions.getAnchorV());
            markerOptions.draggable(customMarkerOptions.isDraggable());
            markerOptions.visible(customMarkerOptions.isVisible());
            markerOptions.zIndex(customMarkerOptions.getZIndex());
        }
        Marker marker = addLatLngToMap(map, latLng, markerOptions);
        markers.add(marker);
    }
    return markers;
}