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)
Related
When I try to place a pin in the center of the map using MKMapView's centerCoordinate it puts a pin roughly in the center, but it's several pixels south of the true center of the map.
I tried converting the map's center point to a coordinate
MKMapView.convertPoint(MKMapView.center) and that worked perfectly on ios8 but on ios7 is still off (now its south and west of the true center).
Anyone know how to determine how "off" the center coordinate is so I can adjust?
I need this because I am placing a crosshair image over the map and need the pin to appear in the center of the crosshair. I've verified with a ruler that the crosshair is centered on the map, it's the pin that is off.
In your answer you fixed one particular scenario where the center coordinate appears to be off, but really is not because it is just partially obscured by the status bar. Unfortunately, it is not as simple as that. There are other edge cases where the center coordinate actually can get offset a bit. (I notice it when I change frame of map view as keyboard is presented and later dismissed.) This is a curious little map view idiosyncrasy.
Anyone know how to determine how "off" the center coordinate is so I can adjust?
Yes, just convert the centerCoordinate to a CGPoint and compare to the center. The only trick is to make sure you do these in the same coordinate system (in the example below, the coordinate system of the map view):
func adjustOverlayCenterYConstraint() {
let mapCenter = mapView.convert(mapView.centerCoordinate, toPointTo: mapView)
let viewCenter = mapView.superview!.convert(mapView.center, to: mapView)
overlayCenterYConstraint.constant = mapCenter.y - viewCenter.y
}
In this example, I have a centerY constraint, whose constant I am adjusting, but it illustrates the idea of how to programmatically determine whether the center is offset a bit and how to adjust it. Theoretically, you might have to adjust the x coordinate, too, but the idea would be the same.
You said:
is still off (now its south and west of the true center)
If it is off both south and west, then the problem is likely just the coordinate system. Remember, center is in the coordinate system of the superview, so make sure to convert to a consistent coordinate system (either get coordinateCenter in coordinate system of map view’s superview and compare to center, or get both in the coordinate system of the mapview, like shown above).
Well I still don't know why in iOS7 MKMapView.convertPoint(MKMapView.center) differs from MKMapView.centerCoordinate, but did figure out why .centerCoordinate was off.
Part of the map was under the status bar and I ruled the center based on the visible part and overlaying images centered on the visible part, but the map computed center based on the whole map. So once I fixed the map not running under the status bar .centerCoordinate works and, on iOS7, works better than MKMapView.center.
I'm displaying a Street View (GMSPanoramaView) via Google Maps SDK for iOS in an iPhone/iPad app and I need to get the final position of a Street View after the user has navigated around in it using gestures, so that I can restore it to the exact position the user moved it to. This is extremely important to be able to do since the Street View is not accurate and often places an address hundreds of yards away from the actual one requested, forcing the user to tap and zoom to move the Street View in front of it. I don't see any delegate methods or API's to get updated coordinates. I can easily track the heading, pitch, zoom, and FOV via the GMSPanoramaViewDelegate didMoveCamera method, but that does not give me updated coordinates. Thus when I restore the Street View using the last heading, pitch, zoom, and FOV values, the Street View displays at the original location but with the heading, pitch, zoom, and FOV applied, which doesn't display the same position as the user expects. Does anyone know how to get (or track) these coordinates? Thanks!
Implement the panoramaView:(GMSPanoramaView*)view didMoveToPanorama:(GMSPanaorama*)panorama on the delegate.
On the GMSPanorama there's a CLLocationCoordinate2d called coordinate - voila.
EDIT
It also appears that at any point in time to can just get the panorama property from the GMSPanoramaView and get the coordinate from there.
I would like to have a annotation in the center of the map, that does not move when the region is changed. That is, when one moves the map, the annotation stays in the center regardless. I have implemented this using NStimer, assigning the map center coordinate to the annotation every .001 seconds, however this is very choppy and doesn't look smooth.
I realize that I need to use an Overlay than convert the overlay annotation to coordinates on the map.
Pretty much it would look like what Uber has.
THe other solutions for this that I have seen have not used a normal annotation. Instead they put another view over the top of the map with the annotation image in the middle. It doesn't matter what happens to the map the view stays centered on the screen and if you do ever need to interact with it, you just ask the map what the center coordinate is at that time.
You can get the code from the following link:
https://github.com/scottrhoyt/CenterPinMapViewController
I have a viewport3d with a camera and some blocks inside of it. Currently using the keyboard to move the camera up/down/left/right/rotate ect.
but instead of the camera i want to move the world view. So when a user presses the W key to move up, its not just moving the camera in a +x position. As the user maybe at a 20 degree view.
Create a virtual Camera Boom.
Create an invisible object like a TDummy, in the same location as the object of interest or the center of the scene.
Create the TCamera as a child of the object. Set its position the desired distance away on one of the axes.
you can now rotate the camera around the object simply by changing the rotationAngle of the dummy object. The camera will maintain the exact distance and automatically points directly toward the center.
Also by adding light as a child of the camera it too will follow as the camera moves. Hope this helps someone.
I have a globe, similar to http://mrdoob.github.com/three.js/examples/webgl_trackballcamera_earth.html.
My globe has some spots on different locations (f.ex. Paris, Rome or London). Whenever one of these spots come into view, a popup window with additional information to that location should popup appear, and again disappears when that spot rotates out of view, quite similar to http://workshop.chromeexperiments.com/cloudglobe/.
You need 3D coordinates of those points and you need to transform(rotate or whatever) them with globe. Then use this code http://www.opengl.org/wiki/GluProject_and_gluUnProject_code to get screen space coordinates of those points. After that it is simple question of HTML, CSS and some javascript. You know where they are on screen so, for example, you can put some absolute positioned divs with text. But you will need to check on which side of globe those spots are - use rotation phase of the sphere or z-coordinate of the point or simple do color-based picking to see if this spot is visible.