Page 68

Android Programming Cookbook

60 / 143

package com.javacodegeeks.androidgooglemapsexample; import import import import import import import import

static static static static static static static static

java.lang.Math.asin; java.lang.Math.atan2; java.lang.Math.cos; java.lang.Math.pow; java.lang.Math.sin; java.lang.Math.sqrt; java.lang.Math.toDegrees; java.lang.Math.toRadians;

import com.google.android.gms.maps.model.LatLng; public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Linear implements LatLngInterpolator { @Override public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lng = (b.longitude - a.longitude) * fraction + a.longitude; return new LatLng(lat, lng); } } public class LinearFixed implements LatLngInterpolator { @Override public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lngDelta = b.longitude - a.longitude; if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360; } double lng = lngDelta * fraction + a.longitude; return new LatLng(lat, lng); } } public class Spherical implements LatLngInterpolator { @Override public LatLng interpolate(float fraction, LatLng from, LatLng to) { double double double double double double

fromLat = toRadians(from.latitude); fromLng = toRadians(from.longitude); toLat = toRadians(to.latitude); toLng = toRadians(to.longitude); cosFromLat = cos(fromLat); cosToLat = cos(toLat);

double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng â&#x2020;?);

SKY MAGZ  

This is Yahya Christian School Magazine

Read more
Read more
Similar to
Popular now
Just for you