Distance of two geo point android - android-mapview

I am new android application developer. I have create a mapview application where i need to calculate the distance of two geo point.How can i do that.

Use the Location.distanceBetween method:
GeoPoint prev, current;
float[] results = new float[3];
Location.distanceBetween(prev.getLatitudeE6()/1E6, prev.getLongitudeE6()/1E6, current.getLatitudeE6()/1E6, current.getLongitudeE6()/1E6, results);

Related

MRTK - Changing Spatial Awareness material at runtime

I would like to change the material of all the spatial meshes at runtime:
If I start the application in Room1, then walk to Room2 and change the material to "newMaterial" I can do that with the following code:
foreach (SpatialAwarenessMeshObject meshObject in observer.Meshes.Values)
{
if (meshObject?.GameObject == null)
continue;
meshObject.Renderer.sharedMaterial = newMaterial;
}
But the above code changes only the visible meshes (so the meshes in Room2). Because if I walk back to Room1 I still have the old material.
So how I can ensure that the material is changed with all the meshes, and not only the visible ones?
I'm using MRTK v2.53 and the XR SDK pipeline
Spatial observer is: WindowsMixedRealitySpatialMeshObserver
To sets the Material to be used when displaying Meshes, it is recommended to change the configuration of Spatial Awareness Mesh Observer instead of change every mesh object. Please refer to the following code:
IMixedRealityDataProviderAccess dataProviderAccess =
CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
if (dataProviderAccess != null)
{
IReadOnlyList<IMixedRealitySpatialAwarenessMeshObserver> observers =
dataProviderAccess.GetDataProviders<IMixedRealitySpatialAwarenessMeshObserver>();
foreach (IMixedRealitySpatialAwarenessMeshObserver observer in observers)
{
// Update the visible material
observer.VisibleMaterial = myMaterial;
}
}

How to resize PIP mode in android

I'm trying to implement a picture-in-picture mode in my app. I'm Implementing google Maps on PIP mode but I can't resize the full-screen map. It always zooms on the map center point. I have done R&D related to this issue but not finding any proper answer. Basically, I need the layout like Whatsapp app pip Screen on my app how to implement it? And my code is here:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Display display=getWindowManager().getDefaultDisplay();
Point size=new Point();
display.getSize(size);
int width=size.x;
int height=size.y;
Rational aspectRatio=new Rational(width,height);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);
}
and here is Manifest code:
<activity android:name=".activities.MainActivity"
android:supportsPictureInPicture="true"
android:resizeableActivity="true"
android:launchMode="singleTask"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>
In this code, I have the screen like
and I want
How can I solve this?
Thanks in advance!!
Just Change Your this code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Display display=getWindowManager().getDefaultDisplay();
Point size=new Point();
display.getSize(size);
int width=size.x;
int height=size.y;
Rational aspectRatio=new Rational(width,height);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);
}
To
Rational aspectRatio = new Rational(3, 4);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);

Phaser.io - Load objects from Tiled

I'm new to phaser, and for the past few days I've been trying to make a really simple game, platformer-style, where the player must navigate to certain areas before being able to exit the level.
I have the basics running, but now I can't seem to figure out how to check if the player is in those areas.
The relevant part of the code so far is as follows:
var game = new Phaser.Game(800, 600, Phaser.AUTO, "mygame", {
preload: preload,
create: create,
update: update,
render: render
});
function preload() {
game.load.tilemap("questMap", "assets/quest.json", null, Phaser.Tilemap.TILED_JSON);
game.load.image("tilesheet", "assets/tilesheet.png");
game.load.image("npc", "assets/npc.png");
game.load.spritesheet("player", "assets/player.png", 64, 64);
}
var map;
var tileset;
var groundBg;
var props;
var houses;
var houseProps;
var npc;
var ground;
var areas;
var player;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = "#A8DBFF";
map = game.add.tilemap("questMap");
map.addTilesetImage("tilesheet");
map.addTilesetImage("npc");
ground = map.createLayer("ground");
groundBg = map.createLayer("groundbg");
props = map.createLayer("props");
houses = map.createLayer("houses");
houseProps = map.createLayer("houseprops");
npc = map.createLayer("npc");
map.setCollisionBetween(1, 5000);
ground.resizeWorld();
Not too pretty, I know.
I've created the map with tiled and there are a lot of small props and decorative tiles, hence the multiple "map.createLayer()" calls. The only one with collision is the ground layer.
Now, on my Tiled file, I've created an Object layer and drawn small rectangles on the areas I want to check if the player is in. I thought this was going to be an easy process but I can't seem to figure out how to load those areas into Phaser, and then check if the player is within bounds.
Googling has given me some results, but none seem to fit, as they usually cover how to add a sprite to an object, which in this case does not apply.
I simply need that small area to exist and check if the player is there. I've also given names to each of those rectangles in Tiled, via the custom properties tab.
I would try using a transparent image as the area you wish to check if your sprite is over and use
if(sprite1.overlap(transparentImage)){
//do something
}

How to listen to android googlemaps geofence transitions

How can i make something happen when my location on a map enters and exits one of my application google map's fence. I cant seem to understand the tutorial of google regarding geofencing. And i cant find any other tutorial of this thing.
this are my code..
#Override
protected void onCreate(Bundle savedInstanceState) {
...
buildGeofence(14.728801, 120.961209, "Id_test", 500);
}
private void buildGeofence(double latitude ,double longitude, String requestId, int radius){
int GEOFENCE_TRANSITION_ENTER = 1;
LatLng geofencePoint = new LatLng(latitude, longitude);
//int radius = 500;
Geofence.Builder geofence = new Geofence.Builder();
geofence.setCircularRegion(geofencePoint.latitude,geofencePoint.longitude, radius);
geofence.setRequestId(requestId);
geofence.setExpirationDuration(Geofence.NEVER_EXPIRE);
geofence.setTransitionTypes(GEOFENCE_TRANSITION_ENTER);
geofence.setNotificationResponsiveness(0);
geofence.build();
CircleOptions circleOptions = new CircleOptions();
circleOptions.center(geofencePoint);
circleOptions.radius(radius);
circleOptions.strokeColor(Color.BLACK);
circleOptions.strokeWidth(2);
circleOptions.fillColor(0x30ff0000);
mMap.addCircle(circleOptions);
}
Dens,
To make something happen when you transition the Geofence you need to
Create an intent for Geofence transitions.
Create a GeofencingRequest.
Add the intent, GeofenceingRequest, and GoogleApiClient to the LocationServices.GeofencingApi API.
Handle the intent.
The code you have written so far will create a geofence and a circle on the map, but it will not yet do anything when the fence is transitioned.
In the tutorial you linked, you successfully created a geofence, but now you need to follow some of the other steps. Make sure you follow the steps in "Specify geofences and initial triggers", "Define an Intent for geofence transitions", and "Add geofences". This should complete steps 1, 2, and 3 that I listed above. One you have those steps working, try the section "Handle Geofence Transitions", which will complete step 4 that I listed above.
I hope this helps you!
P.S.: Since I see you are adding circles to the map, you may quickly discover you need a way to keep track of these circles in order to correctly add and remove them for each geofence. There is a short blog post here that discusses how to do this.

andengine removing collectable objects like Sprites

im developing a game using andangine and the tmx and body2d extensions.
i create Objects(sprites) like coins an specific positions while creating my map.
i use a contactlistener to check if the player collides with a coin.
how can i delete this sprite?
and how can i organize my sprites best?
thanks =)
I assume you create a PhysicsConnector to connect between your sprites and bodies. Create a list of these physics connectors, and when you decide you should remove a body (And its sprite), do the following:
Body bodyToRemove = //Get it from your contact listener
for(PhysicsConnector connector : mPhysicsConnectors) //mPhysicsConnectors is the list of your coins physics connectors.
if(connector.getBody() == bodyToRemove)
removeSpriteAndBody(connector); //This method should also delete the physics connector itself from the connectors list.
About sprites organization: Coins are re-useable sprite, you shouldn't recreate them every time. You can use an object pool, here's a question about this topic.
I advice you to set user data of a body. And in your collision handler you would be able to work with it. Small example:
body.setUserData(...);
..
public void postSolve(Contact contact, ContactImpulse impulse) {
... bodyAType = (...) bodyA.getUserData();
... bodyBType = (...) bodyB.getUserData();
if (bodyAType != null && bodyBType != null) {
if (bodyAType.getUserData.equals(...)) {
//.......do what you need
}
}
}

Resources