I want to rotate marker icon to road direction, as you can see in image it only just placed but its not rotated to road direction.. i've tried below code as far
double lat = 19.205681
double lon = 72.871742
loc.setLatitude(lat);
loc.setLongitude(lon);
Location newLoc = new Location("service Provider");
newLoc.setLongitude(lat);
newLoc.setLongitude(lon);
map.addMarker(new MarkerOptions()
.position(new LatLng(data.getLat(),data.getLon()))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pandu_car))
.anchor(0.5f,0.5f)
.rotation(loc.bearingTo(newLoc))
.flat(true));
Note: marker have individual location (ofcource) i dont want to show from-to location bearing ...only individual marker to face on road direction
Thanks you
UPDATE:i wanna set my marker (car) like this Ola app
I have tried your code, first check that is newLoc has bearing or not?
just made some changes as following, you can try it:
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest,
new com.google.android.gms.location.LocationListener() {
#Override
public void onLocationChanged(Location location1) {
if (location1 != null) {
if (currentPositionMarker != null) {
currentPositionMarker.remove();
}
double latitude = location1.getLatitude();
double longitude = location1.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
if (status == ConnectionResult.SUCCESS) {
currentPositionMarker = googleMap.addMarker(new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.current_position))
.rotation(location1.getBearing()).flat(true).anchor(0.5f, 0.5f)
.alpha((float) 0.91));
} else {
GooglePlayServicesUtil.getErrorDialog(status, activity, status);
}
}
}
});
Following code works perfectly fine.
private double radiansToDegrees(double x) {
return x * 180.0 / Math.PI;
}
double fLat = (Math.PI * past.getLatitude()) / 180.0f;
double fLng = (Math.PI * past.getLongitude()) / 180.0f;
double tLat = (Math.PI * next.getLatitude()) / 180.0f;
double tLng = (Math.PI * next.getLongitude()) / 180.0f;
double degree = radiansToDegrees(Math.atan2(sin(tLng - fLng) * cos(tLat), cos(fLat) * sin(tLat) - sin(fLat) * cos(tLat) * cos(tLng - fLng)));
if (degree >= 0) {
bearing = degree;
} else {
bearing = 360 + degree;
}
marker.rotation((float) bearing);
Related
i am trying to place a marker to a map according to location, and my activity refreshes after every 10 sec so that I can get location from database every 10.
What I am expecting is to change marker location every 10 sec but marker keeps on changing position frequently that is 5 to 6 times every 10 sec.
And my cab marker also keeps on dissapearing I this its the map.clear(), but without it 2 to 4 markers keeps on reappearing
For placing markers
LatLngBounds.Builder builder = new LatLngBounds.Builder();
ArrayList<Marker> markers = new ArrayList<>();
mMap.clear(); // to clear markers and polylines
drivLat1 = driverLocation.getLatitude();
drivLng1 = driverLocation.getLongitude();
drivLat2 = driverChangedLocation.getLatitude();
drivLng2 = driverChangedLocation.getLongitude();
bearingBetweenLocations(drivLat1,drivLng1,drivLat2,drivLng2);
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.car_marker);
markers.add(0,mMap.addMarker(new MarkerOptions().position(new LatLng(driverLocation.getLatitude(), driverLocation.getLongitude()))
.icon(icon)
.title("Driver Location")));
markers.add(1,mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("User Location")));
rotateMarker(markers.get(0), (float) bearingBetweenLocations(drivLat1,drivLng1,drivLat2,drivLng2));
for (Marker marker : markers) {
builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();
int padding = 100;
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mMap.animateCamera(cu);
private double bearingBetweenLocations(double lat11 ,double long11,double lat22 ,double long22) {
double PI = 3.14159;
double lat1 = lat11 * PI / 180;
double long1 = long11 * PI / 180;
double lat2 = lat22 * PI / 180;
double long2 = long22 * PI / 180;
double dLon = (long2 - long1);
double y = Math.sin(dLon) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(dLon);
double brng = Math.atan2(y, x);
brng = Math.toDegrees(brng);
brng = (brng + 360) % 360;
return brng;
}
private void rotateMarker(final Marker marker, final float toRotation) {
if (!isMarkerRotating) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final float startRotation = marker.getRotation();
final long duration = 1000;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
#Override
public void run() {
isMarkerRotating = true;
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed / duration);
float rot = t * toRotation + (1 - t) * startRotation;
marker.setRotation(-rot > 180 ? rot / 2 : rot);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
isMarkerRotating = false;
}
}
});
}
}
And this is how I set accuracy, bcoz I think that this can be a problem
if (location.hasAccuracy()) {
// Accuracy is in rage of 20 meters, stop listening we have a fix
if (location.getAccuracy() < 20) {
LocationServices.FusedLocationApi.removeLocationUpdates(client, this);
}
}
What I want is that markers only change position when data gets updated
I have 3 markers on a Google Map.
Two Markers to show starting and ending points
Here is the code using to draw a Polyline between these two points:
private void polyLine() {
LatLng starting = new LatLng(##.######, ##.######);
LatLng ending = new LatLng(##.######, ##.######);
PolylineOptions line = new PolylineOptions().add(starting, ending);
mGoogleMap.addMarker(new MarkerOptions().position(starting).title("Start"));
mGoogleMap.addMarker(new MarkerOptions().position(ending).title("End"));
mGoogleMap.addPolyline(line);
}
One Marker to show current Location [HUE_ROSE]
And to animate marker to current location using:
#Override
public void onLocationChanged(Location location)
{
Toast.makeText(this, "Location Changed " + location.getLatitude()
+ location.getLongitude(), Toast.LENGTH_LONG).show();
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
if(ourGlobalMarker == null) { // First time adding marker to map
ourGlobalMarker = mGoogleMap.addMarker(new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)));
MarkerAnimation.animateMarkerToICS(ourGlobalMarker, latLng, new LatLngInterpolator.Spherical());
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
} else {
MarkerAnimation.animateMarkerToICS(ourGlobalMarker, latLng, new LatLngInterpolator.Spherical());
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
}
}
PROBLEM:
Getting Animating Marker, but right side of Polyline
SOLUTION:
How Can I show Animated Marker on Polyline Path
I tried a lot to find solution for this one, but did not find any thing, share your suggestions.
I am assuming you have 3 marker
1. Source point
2. Destination Point
3. Moving marker
you have to try this way it will help you
private void animateMarkerNew(final LatLng startPosition, final LatLng destination, final Marker marker) {
if (marker != null) {
final LatLng endPosition = new LatLng(destination.latitude, destination.longitude);
final float startRotation = marker.getRotation();
final LatLngInterpolatorNew latLngInterpolator = new LatLngInterpolatorNew.LinearFixed();
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(2000); // duration 3 second
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
try {
float v = animation.getAnimatedFraction();
LatLng newPosition = latLngInterpolator.interpolate(v, startPosition, endPosition);
marker.setPosition(newPosition);
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(newPosition)
.zoom(18f)
.build()));
marker.setRotation(getBearing(startPosition, new LatLng(destination.latitude, destination.longitude)));
} catch (Exception ex) {
//I don't care atm..
}
}
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
// if (mMarker != null) {
// mMarker.remove();
// }
// mMarker = googleMap.addMarker(new MarkerOptions().position(endPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_car)));
}
});
valueAnimator.start();
}
}
Note: marker is mean which marker you want to animate that one.
private interface LatLngInterpolatorNew {
LatLng interpolate(float fraction, LatLng a, LatLng b);
class LinearFixed implements LatLngInterpolatorNew {
#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;
// Take the shortest path across the 180th meridian.
if (Math.abs(lngDelta) > 180) {
lngDelta -= Math.signum(lngDelta) * 360;
}
double lng = lngDelta * fraction + a.longitude;
return new LatLng(lat, lng);
}
}
}
//Method for finding bearing between two points
private float getBearing(LatLng begin, LatLng end) {
double lat = Math.abs(begin.latitude - end.latitude);
double lng = Math.abs(begin.longitude - end.longitude);
if (begin.latitude < end.latitude && begin.longitude < end.longitude)
return (float) (Math.toDegrees(Math.atan(lng / lat)));
else if (begin.latitude >= end.latitude && begin.longitude < end.longitude)
return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 90);
else if (begin.latitude >= end.latitude && begin.longitude >= end.longitude)
return (float) (Math.toDegrees(Math.atan(lng / lat)) + 180);
else if (begin.latitude < end.latitude && begin.longitude >= end.longitude)
return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 270);
return -1;
}
Try out with setting anchor like follows
mDetailPositionMarker = mDetailGoogleMap.addMarker(new MarkerOptions()
.position(newLatLonValue)
.anchor(0.5f, 0.5f)
.rotation(bearingValue)
.flat(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.biketopicon)));
And make sure your icon will not be having any padding or margin. Avoid unnecessary space in icon image than the content like shown below.
// Animation handler for old APIs without animation support
private void animateMarkerTo(final Marker marker, final double lat, final double lng) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final long DURATION_MS = 3000;
final Interpolator interpolator = new AccelerateDecelerateInterpolator();
final LatLng startPosition = marker.getPosition();
handler.post(new Runnable() {
#Override
public void run() {
float elapsed = SystemClock.uptimeMillis() - start;
float t = elapsed/DURATION_MS;
float v = interpolator.getInterpolation(t);
double currentLat = (lat - startPosition.latitude) * v + startPosition.latitude;
double currentLng = (lng - startPosition.longitude) * v + startPosition.longitude;
marker.setPosition(new LatLng(currentLat, currentLng));
// if animation is not finished yet, repeat
if (t < 1) {
handler.postDelayed(this, 16);
}
}
});
}
call this method inside onLocationChange method and pass location lat and lang then you will see a magic ;)
I need to store all the LatLng points of circle drawn on google map. like :
I have circle and radius(in meter). How to get that?. i tried with the code......
private ArrayList<LatLng> makeCircle(LatLng centre, double radius, float zoom)
{
ArrayList<LatLng> points = new ArrayList<LatLng>();
LatLngBounds.Builder builder = new LatLngBounds.Builder();
double EARTH_RADIUS = 6378100.0;
for (double t = 0; t <= Math.PI * 2; t += 1.0)
{
double rad = radius + zoom * EARTH_RADIUS;
double latPoint = centre.latitude + (rad / EARTH_RADIUS) * Math.sin(t);
double lonPoint = centre.longitude + (rad / EARTH_RADIUS) * Math.cos(t) / Math.cos(centre.latitude);
points.add(new LatLng(latPoint * 180.0 / Math.PI, lonPoint * 180.0 / Math.PI));
Marker customMarker = map.addMarker(new MarkerOptions()
.position(new LatLng(latPoint,lonPoint)));
builder.include(new LatLng(latPoint,lonPoint));
LatLngBounds bound = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bound, width-100, height-100, 20);
map.animateCamera(cu);
}
return points;
}
but i m getting points but not on exact locations. i am getting this
How to solve this?
The 'zoom' factor is not relevant for the calculations here. Update your makeCircle() method as shown below and it will work exactly the way you want:
private ArrayList<LatLng> makeCircle(LatLng centre, double radius)
{
ArrayList<LatLng> points = new ArrayList<LatLng>();
double EARTH_RADIUS = 6378100.0;
// Convert to radians.
double lat = centre.latitude * Math.PI / 180.0;
double lon = centre.longitude * Math.PI / 180.0;
for (double t = 0; t <= Math.PI * 2; t += 0.3)
{
// y
double latPoint = lat + (radius / EARTH_RADIUS) * Math.sin(t);
// x
double lonPoint = lon + (radius / EARTH_RADIUS) * Math.cos(t) / Math.cos(lat);
// saving the location on circle as a LatLng point
LatLng point =new LatLng(latPoint * 180.0 / Math.PI, lonPoint * 180.0 / Math.PI);
// here mMap is my GoogleMap object
mMap.addMarker(new MarkerOptions().position(point));
// now here note that same point(lat/lng) is used for marker as well as saved in the ArrayList
points.add(point);
}
return points;
}
I am sure it helped you :)
I've looked through the documentation of polyline and there is no option to make it dashed.
Do anybody know how to draw dashed polyline with android google map sdk v2?
Now in Polyline you can set the pattern to be Dash, Dot or Gap
simply apply the following
public static final int PATTERN_DASH_LENGTH_PX = 20;
public static final int PATTERN_GAP_LENGTH_PX = 20;
public static final PatternItem DOT = new Dot();
public static final PatternItem DASH = new Dash(PATTERN_DASH_LENGTH_PX);
public static final PatternItem GAP = new Gap(PATTERN_GAP_LENGTH_PX);
public static final List<PatternItem> PATTERN_POLYGON_ALPHA = Arrays.asList(GAP, DASH);
private void drawDashedLeg(GoogleMap googleMap, Route route) {
PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(getContext(), R.color.coolgrey));
polyOptions.addAll(route.getPoints());
polyOptions.pattern(PATTERN_POLYGON_ALPHA);
Polyline polyline = googleMap.addPolyline(polyOptions);
polylines.add(polyline);
}
It is not possible in current release. Follow this issue for updates: https://code.google.com/p/gmaps-api-issues/issues/detail?id=4633
UPDATE
Recently, Google implemented this feature for polylines in Google Maps Android API v2 and marked issue 4633 as Fixed.
See information about stroke patterns in the Shapes Guide. See an example in the Polylines and Polygons tutorial.
You can also read the corresponding blog post here:
https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html
Alexey, I've just created a function that worked for me and I think that will help you:
public static void createDashedLine(GoogleMap map, LatLng latLngOrig, LatLng latLngDest, int color){
double difLat = latLngDest.latitude - latLngOrig.latitude;
double difLng = latLngDest.longitude - latLngOrig.longitude;
double zoom = map.getCameraPosition().zoom;
double divLat = difLat / (zoom * 2);
double divLng = difLng / (zoom * 2);
LatLng tmpLatOri = latLngOrig;
for(int i = 0; i < (zoom * 2); i++){
LatLng loopLatLng = tmpLatOri;
if(i > 0){
loopLatLng = new LatLng(tmpLatOri.latitude + (divLat * 0.25f), tmpLatOri.longitude + (divLng * 0.25f));
}
Polyline polyline = map.addPolyline(new PolylineOptions()
.add(loopLatLng)
.add(new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng))
.color(color)
.width(5f));
tmpLatOri = new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng);
}
}
I created the following function to draw dotted polyline with a list of LatLng points.
This algorithm creates lines of 0.002 kms (followed by 0.002 kms meter gaps) irrespective of zoom. This is useful when you don't want to re-plot polylines when zoom changes.
private void drawDashedPolyLine(GoogleMap mMap, ArrayList<LatLng> listOfPoints, int color) {
/* Boolean to control drawing alternate lines */
boolean added = false;
for (int i = 0; i < listOfPoints.size() - 1 ; i++) {
/* Get distance between current and next point */
double distance = getConvertedDistance(listOfPoints.get(i),listOfPoints.get(i + 1));
/* If distance is less than 0.002 kms */
if (distance < 0.002) {
if (!added) {
mMap.addPolyline(new PolylineOptions()
.add(listOfPoints.get(i))
.add(listOfPoints.get(i + 1))
.color(color));
added = true;
} else {/* Skip this piece */
added = false;
}
} else {
/* Get how many divisions to make of this line */
int countOfDivisions = (int) ((distance/0.002));
/* Get difference to add per lat/lng */
double latdiff = (listOfPoints.get(i+1).latitude - listOfPoints
.get(i).latitude) / countOfDivisions;
double lngdiff = (listOfPoints.get(i + 1).longitude - listOfPoints
.get(i).longitude) / countOfDivisions;
/* Last known indicates start point of polyline. Initialized to ith point */
LatLng lastKnowLatLng = new LatLng(listOfPoints.get(i).latitude, listOfPoints.get(i).longitude);
for (int j = 0; j < countOfDivisions; j++) {
/* Next point is point + diff */
LatLng nextLatLng = new LatLng(lastKnowLatLng.latitude + latdiff, lastKnowLatLng.longitude + lngdiff);
if (!added) {
mMap.addPolyline(new PolylineOptions()
.add(lastKnowLatLng)
.add(nextLatLng)
.color(color));
added = true;
} else {
added = false;
}
lastKnowLatLng = nextLatLng;
}
}
}
}
private double getConvertedDistance(LatLng latlng1, LatLng latlng2) {
double distance = DistanceUtil.distance(latlng1.latitude,
latlng1.longitude,
latlng2.latitude,
latlng2.longitude);
BigDecimal bd = new BigDecimal(distance);
BigDecimal res = bd.setScale(3, RoundingMode.DOWN);
return res.doubleValue();
}
Util class to calculate distance between two LatLng:
public class DistanceUtil {
public static double distance(double lat1, double lon1, double lat2,
double lon2) {
if ((lat1 == lat2) && (lon1 == lon2)) {
return 0;
} else
return distance(lat1, lon1, lat2, lon2, 'K');
}
public static double distance(double lat1, double lon1, double lat2,
double lon2, char unit) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
* Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
if (unit == 'K') {
dist = dist * 1.609344;
} else if (unit == 'N') {
dist = dist * 0.8684;
}
return (dist);
}
private static double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}
private static double rad2deg(double rad) {
return (rad * 180.0 / Math.PI);
}
}
Note: The above algorithm generates very large number of polylines which may take time to render. It is useful only when the list of points is small.
I am having trouble in converting the latitude and longitude values into android esri arcGIS map Point. Here's my code to get latitude and longitude values from GPS coordinates:
LocationManager lm;
String towers;
double lat;
double longi;
TextView txt;
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = lm.getBestProvider(crit, false);
Location location = lm.getLastKnownLocation(towers);
if(location != null)
{
lat = location.getLatitude();
longi = location.getLongitude();
}
now I have the latitude and longitude values. Now all I need is to convert these values into valid esri arcGIS MapPoint. Can anyone help me?
Thanks in advance.
Assuming you're using the ESRI Android API? If so, create a graphics layer on your map. Then create a point object
com.esri.core.geometry.Point
Point myPoint = new Point();
then set the x/y values:
myPoint.setX(longi);
myPoint.setY(lat);
then add myPoint to the graphics object.
http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/index.html
Yes, it is possible. But you don't use the locationmanager in ArcGis.
ArcGIS has the predefined method like LocationListener, that is: OnStatusChangedListener.
See the below code for converting location latitude and longitude into esri arcGIS MapPoint.
mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
/**
*
*/
private static final long serialVersionUID = 1L;
public void onStatusChanged(Object source, STATUS status) {
if (source == mMapView && status == STATUS.INITIALIZED) {
LocationService ls = mMapView.getLocationService();
ls.setAutoPan(false);
ls.setLocationListener(new LocationListener() {
boolean locationChanged = false;
// Zooms to the current location when first GPS fix
// arrives.
public void onLocationChanged(Location loc) {
if (!locationChanged) {
locationChanged = true;
double locy = loc.getLatitude();
double locx = loc.getLongitude();
Point wgspoint = new Point(locx, locy);
Point mapPoint = (Point) GeometryEngine.project(wgspoint,
SpatialReference.create(4326),
mMapView.getSpatialReference());
Unit mapUnit = mMapView.getSpatialReference().getUnit();
double zoomWidth = Unit.convertUnits(
SEARCH_RADIUS, Unit.create(LinearUnit.Code.MILE_US), mapUnit);
Envelope zoomExtent = new Envelope(mapPoint, zoomWidth, zoomWidth);
mMapView.setExtent(zoomExtent);
GraphicsLayer gLayer = new GraphicsLayer();
PictureMarkerSymbol symbol = new
PictureMarkerSymbol(getResources().getDrawable(R.drawable.twiz_car_red));
Graphic graphic = new Graphic(mapPoint, symbol);
//Graphic point=new Graphic(new Point(x, y),new
SimpleMarkerSymbol(Color.CYAN,20,STYLE.CIRCLE));
gLayer.addGraphic(graphic);
mMapView .addLayer(gLayer);
}
}
public void onProviderDisabled(String arg0) {
}
public void onProviderEnabled(String arg0) {
}
public void onStatusChanged(String arg0, int arg1,
Bundle arg2) {
}
});
ls.start();
}
}
});
I've borrowed some code from here
private Point ToGeographic(Point pnt)
{
double mercatorX_lon = pnt.getX();
double mercatorY_lat = pnt.getY();
if (Math.abs(mercatorX_lon) < 180 && Math.abs(mercatorY_lat) < 90)
return pnt;
if ((Math.abs(mercatorX_lon) > 20037508.3427892) || (Math.abs(mercatorY_lat) > 20037508.3427892))
return pnt;
double x = mercatorX_lon;
double y = mercatorY_lat;
double num3 = x / 6378137.0;
double num4 = num3 * 57.295779513082323;
double num5 = Math.floor((double)((num4 + 180.0) / 360.0));
double num6 = num4 - (num5 * 360.0);
double num7 = 1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * y) / 6378137.0)));
mercatorX_lon = num6;
mercatorY_lat = num7 * 57.295779513082323;
return new Point(mercatorX_lon, mercatorY_lat);
}
private Point ToWebMercator(Point pnt)
{
double mercatorX_lon = pnt.getX();
double mercatorY_lat = pnt.getY();
if ((Math.abs(mercatorX_lon) > 180 || Math.abs(mercatorY_lat) > 90))
return pnt;
double num = mercatorX_lon * 0.017453292519943295;
double x = 6378137.0 * num;
double a = mercatorY_lat * 0.017453292519943295;
mercatorX_lon = x;
mercatorY_lat = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
return new Point(mercatorX_lon, mercatorY_lat);
}
I make no claims of efficiency, but it's a starting point at least.
Disclaimer: I'm not an expert in this, but want to try to help. :)
There is now an ArcGIS Stack Exchange site. There's more information being added all the time and is a nice consolidated resource compared to what is out there disbursed on the interwebs.
For frameworks, I recommend GeoTools for Android.
As an aside, QGIS for Android is an interesting project from Marco Bernasocchi which you may find helpful as a reference.
Hope you can find what you're looking for!
i made a function that converts the two parameters of a location point to arcgis point :
private Point ConvertMyLocationPoint(final double x, final double y) {
Point wgspoint = new Point(x, y);
Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326),
mMapView.getSpatialReference());
return mapPoint;
}
//convert longitude and latitude to map point X Y
- (AGSPoint *)agsPointFromLatitude:(double)latitude longitude:(double)longitude
{
double mercatorX = longitude * 0.017453292519943295 * 6378137.0;
double a = latitude * 0.017453292519943295;
double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));
AGSPoint *obj = [AGSPoint pointWithX:mercatorX y:mercatorY spatialReference: [AGSSpatialReference wgs84SpatialReference]];
return obj;
}