I'm working on an app where manual interaction with map is not allowed. The only way to change the map is as user is moving towards a direction. So if a user rotates the phone rotates and so based on the compass in iPhone the map should rotate automatically rather than user rotating it to the direction by 2 fingers gestures. Here is a picture that clear the idea a little more:
Consider the red dot as my location and as I rotate my phone I want google map to rotate with it. So my question is that how this can be achieved? As there is a method I found [_myMap animateToViewingAngle:45]; after searching but this didn't did what I was looking for.
EDIT I thought of this is there any way we can convert lat and long values to angle?
You can use the course property from the CLLocation and pass it to the animateToBearing method of your GMSMapView. From the documentation:
Swift
var course: CLLocationDirection { get }
Objective-C
#property(readonly, nonatomic) CLLocationDirection course
Discussion
Course values are measured in degrees starting at due north and continuing clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on. Course values may not be available on all devices. A negative value indicates that the direction is invalid.
Related
I want to rotate apple map based on user's driving direction,
Any idea or solution to rotate map like that way?
I can collect array of last 5-10 moved location, but based on it, Can I calculate heading or anything else to rotate map?
It seems HitResult only gives us intersection with a surface (plane) or a point cloud. How can I get a point in the middle of air with my click, and thus put an object floating in the air?
It really depends on what you mean by "in the air". Two possibilities I see:
"Above a detected surface" Do a normal hit test against a plane, and offset the returned pose by some Y distance to get the hovering location. For example:
Pose.makeTranslation(0, 0.5f, 0).compose(hitResult.getHitPose())
returns a pose that is 50cm above the hit location. Create an anchor from this and you're good to go. You also could just create the anchor at the hit location and compose with the y translation each frame to allow for animating the hover height.
"Floating in front of the current device position" For this you probably want to compose a translation on the right hand side of the camera pose:
frame.getPose().compose(Pose.makeTranslation(0, 0, -1.0f)).extractTranslation()
gives you a translation-only pose that is 1m in front of the center of the display. If you want to be in front of a particular screen location, I put some code in this answer to do screen point to world ray conversion.
Apologies if you're in Unity/Unreal, your question didn't specify so I assumed Java.
The reason why you see so often a hit result being interpreted as the desired position by the user is that actually there is no closed-form solution for this user interaction. Which of the infinite possible positions along the ray starting from the camera pointing towards the scene was desired by the User? 2D coordinates from a click still leave the third dimension undefined.
As you said "middle of the air", why not take the centre between the camera position and the hitresult?
You can extract the current position using pose.getTranslation https://developers.google.com/ar/reference/java/com/google/ar/core/Pose.html#getTranslation(float[],%20int)
I am working on a program that should detect the pins on the map when the user is approaching to some distance, and the pin has to be in a certain angle of view. I have imported MapKit and added all pins to the annotation. Now my app is working but takes into account all pins in the map. I need to take into account only the pins that are in a 30 degree of angle. How to do this?
I think that you are asking how to change the angle of the view so the pins near the distance you say are visible in a different perspective, if im correct this is the answer:
You need to use the method setCamera on the MKMpaView, this receives an MKMapCamera, you can instantiate a camera like this let camera = MKMapCamera(lookingAtCenter:CLLocationCoordinate2D, fromDistance: CLLocationDistance, pitch: CGFloat, heading: CLLocationDirection)
where pitch is the angle, all the other parameters are super clear. when you create the camera the you jus call map.setCamera(camera: camera, animated: true) and thats it.
It's not written anywhere in the documentation, but it's still being able to calculate the viewing angle of MKMapCamera manually. For instance, SCNCamera has a property called fieldOfView, which is vertical viewing angle and it equals 60 degree. If MKMapCamera had the same property, it would be 30 degree.
I have an GPS based iPhone application that uses Google Maps. The app simply displayes the users current location on the map and will alert users when they come to within a certain radius of a marked Point on their journey.
For legal reasons I am unable to use turn-by-turn navigation in the app so the app will never know the route the user is taking to get from A to B. All the app does is constantly check current location agains a database of GPS Point coordinates. If the users current location is within e.g. 50 meters of a Point, the user will get a message regarding that Point.
My issue is this:
Each Point has a radius of say 50 meters around it as marked by the large blue circle on the image below.
The user is indicated by small blue dot and the direction of travel is marked by the red arrow. In the image the user has entered the radius of the Point but is not actually on the same road as the Point. The user should only get messages should they be on the same road as the Point and within the radius of the Point.
Is there a way I can determine if the user is on the same road as thePoint when entering that Points radius?
Side Note: The app is working in its current state and I can get messages when entering the radius of a Point.
I have been implementing gps based track and trace apps for a while. The easiest way I see is when you get the event that the point is entering the 50 m radius you do a geolookup meaning you ask the system the address of the long/lat. You compare this (street) with the geolookup of your ref point.
This requires a geolookup service and the user being online.
Instead of using a circle, you should use a rectangle defined when creating each point. Or use both: test rectangle of the street once inside the circle if your rectangle is too approximate. You can find out approximate edges of the rectangle by testing geolookup different point of the circles at the beginning.
The case is the replicate the north pole indicator into a button and perform the rotation.I know this can be done by rotating the map view entirely.Is there any other neat way where the annotation stays normal to the ipad orientation even after rotation
EDIT
as #AlexWain says
mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading
is an excellent solution ...but only possible when the user location displayed on map while rotating it
I need just to show a region and point the map towards north on the button click and sadly it is not the users current location,and is not in visible at that time
Apple has introduced that feature:
Use mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading
This turns the map in the direction you are looking or moving.
In that case north on the map matches the direction of north.
Update:
If the location is outside of the view, there is NO neat way to do it.
You have to rotate the view, and apply the inverse rotation to all elements which should not be rotated (e.g annotations, pins, copyright label)