How can I encode a circle in android maps? - android

I know that we can encode a polygon in android like this:
encoded_string = polyutil.encode(polygon.getPoints());
But how can we get a encoded string for a circle?

I don't know what polyutil is or what its encode method does, but a circle's equivalent of a polygon's points is the center and radius. It shouldn't be too hard to call getCenter() and getRadius() on the circle and make a string with that data in it.
https://developer.android.com/reference/com/google/android/gms/maps/model/Circle.html

You may be able to use Java Topology Suite to do it.
http://mvnrepository.com/artifact/com.vividsolutions/jts/1.11
Coordinate center = new Coordinate(entity.getLongitude(), entity.getLatitude());
GeometricShapeFactory gsf = new GeometricShapeFactory();
gsf.setCentre(center);
gsf.setNumPoints(20);
gsf.setSize(10.2);
Polygon poly = gsf.createCircle();
Coordinate[] coordArray = poly.getCoordinates();
Not sure if this is what you want, but it'll give you an array of Coordinates on the perimeter of the circle, so it may be worth playing around with.

Related

How to set a polygon over the region surrounding the Route at certain distance (in HereMaps)

I tried getting BoundingBox of route instance and set the polygon over it but the result was a rectangle over the route as shown in the image below which is inappropriate.
Also, I tried to add the BoundingBox of some color with alpha value for transparency over the geocoordinates in the route with a certain distance but the polygons were overlapping and hiding the visibility of Route, like in the image below. Note: (Red circle shows the route which is somewhat visible at certain location due to less overlapping)
I am unable to find any way using which I can merge the multiple polygons into one giant polygon surrounding the route like in 2nd image.
Below is my code which provided me the results in the 2nd image.
fun addBoundingBoxTo(center: GeoCoordinate) {
val boundingBox = GeoBoundingBox(center, 1000f, 1000f)
val coordinates: MutableList<GeoCoordinate> = ArrayList()
coordinates.add(boundingBox.topLeft)
coordinates.add(GeoCoordinate(boundingBox.topLeft.latitude,
boundingBox.bottomRight.longitude,
boundingBox.topLeft.altitude))
coordinates.add(boundingBox.bottomRight)
coordinates.add(GeoCoordinate(boundingBox.bottomRight.latitude,
boundingBox.topLeft.longitude, boundingBox.topLeft.altitude))
val geoPolygon = GeoPolygon(coordinates)
val polygon = MapPolygon(geoPolygon)
polygon.fillColor = Color.parseColor("#77777777")
polygon.lineWidth = 0
map.addMapObject(polygon)
}
route.routeGeometry.forEach {
addBoundingBoxTo(it)
}
The desired result I want to achieve is like in the below image:
Any help would be appreciated. Thanks!
With the latest December release, can now also specify up to 20 polygons in a routing request. This allows a more precise and simple way to define areas that should be avoided.

How to get boundaries of WorldWind's globe in geographic coordinates

I have implemented WorldWind in my application. I need to get the visible portion of the globe so that I can find the Northeast and Southwest latitude and longitude coordinates of this visible part.
How do I get the boundaries of the visible part of the globe?
The question can be complicated. For example, if the horizon is visible, then your view is not bounded by four geodetic positions.
If you are in a method that provides a DrawContext, there is a convenience method for returning the visible sector:
Sector visibleSector = dc.getVisibleSector();
LatLon[] corners = visibleSector.getCorners();
If you don't have access to the DrawContext, but you can guarantee that all four corners of your view will intersect the globe, then you can use the following snippet from the worldwind forums:
View view = WorldwindCore.getInstance().getWw().getView();
Rectangle viewport = view.getViewPort();
LatLon corners[] = new LatLon[4];
corners[0] = view.computePositionFromScreenPoint(viewport.getMinX(), viewport.getMinY());
corners[1] = view.computePositionFromScreenPoint(viewport.getMinX(), viewport.getMaxY());
corners[2] = view.computePositionFromScreenPoint(viewport.getMaxX(), viewport.getMaxY());
corners[3] = view.computePositionFromScreenPoint(viewport.getMaxX(), viewport.getMinY());

Android compute right bbox for WMS getFeatureInfo

I'm trying to make a request to my Geoserver to retrieve the features near the tap of a user on the map.
The map takes all the space. Therefore I computed the BBOX in this way:
region = mMap.getProjection().getVisibleRegion().latLngBounds;
double left = region.southwest.longitude;
double top = region.northeast.latitude;
double right = region.northeast.longitude;
double bottom = region.southwest.latitude;
and the width and height are taken as belows:
mMapFragment.getView().getWidth();
mMapFragment.getView().getHeight();
while the X and Y parameter are calculated in the following way:
Point click = mMap.getProjection().toScreenLocation(latLng);
where latLng is the point that came from the event onMapClick(LatLng) (reference here: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMapClickListener).
The resulting URL that I obtain is:
http://localhost/geoserver/sindot/wms?service=WMS&request=GetFeatureInfo&info_format=application%2Fjson&version=1.1.1&srs=EPSG%3A3857&bbox=1222173.74033,5056403.44084,1222174.11356,5056403.7028&query_layers=sindot:verticale&layers=sindot:verticale&feature_count=3&styles=tabletb3lab&width=2048&height=1262&x=1441&y=503
The problem is that the server returns always an empty response even if I know that there are features there because I can see the spots on the map. What could it be?
Thanks in advance.
It onlytook to add &buffer=10 (or another number according to your needs) to the request.

How to find Center Point from geometry arcgis android?

I am developing one application in that i want to show call out in center of geometry on my map I am new to arcgis.I tried so much but i am unable to get call out in center,please anybody help me how to solve this problem
my code
SimpleFillSymbol sfs = new SimpleFillSymbol(
Color.RED);
sfs.setAlpha(5);
graphic = new Graphic(feature.getGeometry(),
sfs, feature.getAttributes());
Polygon polygon = (Polygon) graphic
.getGeometry();
int polygonpointscount=polygon.getPointCount();
if(polygonpointscount!=0)
{
pointsize=polygonpointscount/2;
}
Point midpoint = polygon.getPoint(pointsize);
Callout callout = mMapView.getCallout();
if (callout != null
&& callout.isShowing()) {
callout.hide();
}
//Set the content, show the view
callout.setContent(adminsearchloadView(governorate_Name,
area_Name,
block_Number));
callout.setStyle(R.xml.calloutstyle);
callout.setMaxHeight(100000);
callout.setMaxWidth(100000);
callout.refresh();
callout.show(midpoint);
Short answer: use GeometryEngine.getLabelPointForPolygon(Polygon, SpatialReference).
Long answer:
From your code...
int polygonpointscount=polygon.getPointCount();
if(polygonpointscount!=0)
{
pointsize=polygonpointscount/2;
}
Polygon.getPointCount() returns the vertices of the polygon. For example, if the polygon is a rectangle, getPointCount() returns the corners. So your Callout will be at one of the corners instead of at the centroid.
Instead, use GeometryEngine.getLabelPointForPolygon(Polygon, SpatialReference) . It doesn't guarantee to return the centroid, but it returns an interior point that is good for labeling (and it looks like the centroid to me). Make sure you pass a SpatialReference object that tells getLabelPointForPolygon what the spatial reference of your polygon is.
If you must have the centroid, you'll need to create a geoprocessing service based on ArcGIS's Feature to Point tool. However, getLabelPointForPolygon is much easier to implement and faster to execute and probably satisfies your need.
If you use arcgis server you can try "feature to point": http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000003m000000 to calculate centroid layer.

Box2d - Is there a way to check whether there is a body at a specific location?

In my game, a body is randomly relocated on the screen after the user does something. However, if the object is relocated on top of another body, then both are pushed slightly (to make room!). I would like to check the location of the randomly generated coordinates first, so that the relocation only takes place if the position is free (within a certain diameter anyway).
Something like.. location.hasBody(). There surely must be a function for this that I haven't found. Thanks!
There is no way to query a world with a point and get the body, but what you can do is query the world with a small box:
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
// Query the world for overlapping shapes.
QueryCallback callback(p);
m_world->QueryAABB(&callback, aabb);
if (callback.m_fixture)
{
//it had found a fixture at that position
}
Solution originally posted here: Cocos2d-iphone forum
Not sure if box2d includes a 'clean' way to do it. I'd just manually iterate over all bodies in the world just before adding a new one, and manually check if their positions + radio/size overlap with the new body shape.
try
b2Vec2 vec = body->GetPosition(); // in meters
or
CGPoint pos = ccp(body->GetPosition().x * PTM_RATIO, body->GetPosition().y * PTM_RATIO); // in pixels

Categories

Resources