MapKit: go to max zoom - ios7

I have tried a few solutions but haven't found one that works for me. Basically, when a button is pressed on my mapview, I want to zoom in as far as MapKit allows, with the user location centered. I keep trying to manipulate the distance parameters, but it seems below a certain point that no longer works...the map view will only zoom to a certain distance, but I can manually pinch and zoom further beyond that. Obviously I don't expect it to give me a 10x10m map...but as close as possible.
Actually, ideally I'd like to do this in combination with using the "follow with heading" tracking mode...but I've found that setting this property will automatically set the zoom level to some predefined point, which is annoying. I think I'll have to manually track heading and rotate the map...a little frustrating that the API doesn't give us a little more flexibility. And it seems like "[mapView maxZoom]" would be a really useful call, but I've found no such thing...what am I missing?
-(void)zoomAndCenterMap
{
CLLocationCoordinate2D coord = self.mapView.userLocation.coordinate;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coord, 10, 10);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];
[self.mapView setRegion:adjustedRegion animated:YES];
}

A maxZoom API does indeed not exist in MapKit. I've added a method to a subclass of MKMapView over in another project that might be of use. Then you could at least figure out what the max zoom level is and maybe programmatically go to it.

Related

Is there a way I can let the camera zoom but not rotate?

Is there a way I can let the SceneKit's camera zoom but not rotate? And how can I delimitate the maximum and minimum zoom the user can do with the camera?
It depends what you mean by zoom – if you mean to do the same thing as 'zooming' a camera lens, you want to modify the yFov and xFov (field of view) attributes of the SCNCamera object. The camera stays in the exact same location, but changes its field of view like a zoom lens.
I cannot see how you can rotate the camera while zooming it – I’d need to see more context of where you’re using the camera. If you don’t touch the SCNNode the camera is attached to, you can’t possibly rotate it.
You're talking about user camera movement with allowsCameraControl, right? I don't think that's really meant to be the basis for a sophisticated user camera movement scheme, more of a simple debugging aid. If you really want fine control over how the user can move the camera, you're best served by creating your own camera node and moving it / changing its properties in response to whatever user input you want to handle (gesture recognizers, game controllers, etc).
I suppose you might be able to constrain the automatic user camera by implementing a scene renderer delegate willRenderScene method. You'd have to get the current pointOfView node, check its position and camera parameters, and change them if they're outside whatever bounds you want. But A) I'm not sure this would work, and B) it's probably not a great idea — it's sort of like messing with the internal view hierarchy of a system control class.

How to scale custom pins MKMapKit

I Have just added a custom pin image to a pin on my map. The problem is that the pin is quite large and covers a lot of the map this is fine zoomed in but is a problem when zoomed out as the user cant see any of the map.
How can I make the pin scale down when the user zooms out?
I have googled it but cant seem to find any answers.
Here is my code
Does any one know how to do this or where I can find out how?
Thanks!
From "Location Awareness Programming Guide":
All annotations are drawn at the same scale every time, regardless of the map’s current zoom level.
You need to track zoom level of the map and do change image size for annotation.
Hope, this will help: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
You should review one or two tutorials on using mapkit to see how it's done. A map pin implemented as an MKMapAnnotationView will always scale properly (it will always stay the same size while the map scale changes.
Try looking over this tutorial by Ray Wenderlich. There is a lot to digest, but the main points to refer to are how to use the MKAnnotation protocol (see the MyLocation class in this tutorial), how pins are actually added as "annotations" (see the - (void)plotCrimePositions:(NSString *)responseString method), and, finally, how the MKMapViewDelegate methods are used, particularly - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation.

NSWindow attached to cursor

I would like to make a custom panel, that shows a zoom at the current cursor-location.
Like for example 'Sip' does.
I have searched the web for examples, but didn't find anything specific.
I found NSEvent's addGlobalMonitorForEventsMatchingMask:handler: and addLocalMonitorForEventsMatchingMask:handler: methods.
Now I could just set the frame origin of the window.
But I'm not sure if that's really the right solution.
Is there a better way to do this?
Could anyone point me into some sample-code?
That's basically it.
You can also use the Quartz Event Tap function family CGEventTap, as it will provide a little more responsiveness during events like the Mac application switcher and Exposé or Mission Control or Dashboard. However, it is a little harder to set up, and uses a C callback approach that is a little tougher to use with some things.
Quartz Event Taps are otherwise the same thing, but possibly slightly faster.
If you use that, be sure to use the function CGPoint CGEventGetUnflippedLocation(CGEventRef aCGEvent)
As in:
CGPoint eventLocation = CGEventGetUnflippedLocation(aCGEvent);
That will make sure your y coordinates are bottom left like the rest of Cocoa.
Otherwise use its sibling CGEventGetLocation() which for some odd reason of crappy naming doesn't indicate that it returns flipped coordinates. (but the docs do state this)

Animating a marker pin on Bing Maps for Metro apps

I have a Bing Map control and I want to animate the location of a pin drawn on the map.
Ideally I'd want to write code like this:
// Image myPin = some Image on the map layer;
var sb = new Storyboard();
var duration = DurationHelper.FromTimeSpan(System.TimeSpan.FromMilliseconds(1000));
sb.Duration = duration;
LocationAnimation ani = new LocationAnimation();
ani.To = new Location(33.3, 11.1); // destination lat, lng
ani.Duration = duration;
sb.Children.Add(ani);
Storyboard.SetTarget(ani, myPin);
Storyboard.SetTargetProperty(ani, "MapLayer.Position");
Resources.Add("moveMyPin", sb);
sb.Begin();
Of course there is no LocationAnimation class in the framework. There are a couple similar: PointAnimation works with the Point type, while DoubleAnimation works with individual double values.
I assumed I have to implement my Timeline-derived class but the documentation I found so far is not helpful in this regard and I don't know where to start.
How to animate a property for which there is no *Animation class ready? Am I missing something?
Update: I think I can do something like
// let aniX and aniY be two DoubleAnimation objects
StoryBoard.SetTargetProperty(aniX, "(MapLayer.Position).Latitude")
StoryBoard.SetTargetProperty(aniY, "(MapLayer.Position).Longitude")
but now I have another problem as I don't see how to animate the attached property and always get an exception like "Cannot resolve TargetProperty (MapLayer.Position).Latitude on specified object."
So I guess the question now becomes: how to specify a property path for an attached property?
Further update: I may be on a wrong lead with the "SetTargetProperty" thing as that would make a dependent animation (see link in comments). Could there be a better way to animate a marker pin to a coordinate destination?
Update 3: as Jared pointed out I could try to animate RenderTransform, or use a transition to achieve my result. I had already gone this way and it doesn't seem to be my solution. This is what I found out:
Using RepositionThemeAnimation, it seems I have to give the new pixel position of the pin. This is problematic for a couple reasons: first, I know the lat/lng destination of the pin, but would have to work out the projection (as far as I can tell there is no public interface to work with projection). Secondly the projection itself can change as the map zooms/pans. The pixel destination at the time of the end of the animation could not be the same as the initial pixel destination. In my scenario it's a major problem as it's very likely the map is moving while the animation is occurring.
Using RepositionThemeTransition all the weird pixel/projection problems went away. It's the only way so far I was able to see the animation I expected. I just set the transition and set the new lat/lng position of the tag (via MapLayer.SetPosition). It has two major problems though. I can't set the duration (nor the easing functions) for the animation. And most importantly I can see no way to execute code when the pin gets to its final position.
Attached properties can be animated, but you must enclose their names in parenthesis. See an example here:
http://www.charlespetzold.com/blog/2007/09/080231.html
However, I believe this only works for setting the whole value (Location) and potentially not sub properties (Latitude and Longitude).
I'm wondering if you can provide more information about what you're trying to do. Is this a temporary animation? i.e. are you wanting the pin to animate in on entrance or departure? If so you can just do an animation on the RenderTransform X and Y instead. You won't actually be changing the location of the pin but you can use the RenderTransform to temporarily change where it's being drawn.
Even better, you might be able to get away with the free animations now built into the framework. You don't even need a storyboard to use them, you just set them right on the element like this:
<Button Content="Transitioning Button">
<Button.Transitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Button.Transitions>
</Button>
For more examples of the animation library and even video previews for many of the animations, see:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452703.aspx
Okay, man, your problem isn't related to Bing Maps. It's related to dependency properties that can't be animated UNLESS you specify that they can. Here's how: http://blog.jerrynixon.com/2012/06/windows-8-animated-pie-slice.html
That link in the other answer with Charles' site is not up to date.

how to create a map base on the user coordinates?

How do I create an app that would takes map coordinates & map size enter by a user, and then draws that desired map? I looked, couldn't fine any video either. All the map tutorial show is how to create a app for your current location.
Thank
Most of the examples you've found are totally valid, you only need to provide the coordinates of the map you want to display in addition to that. That's the easy part...
It's usually as easy as
MKCoordinateRegion region = MKCoordinateRegionMake (60,0,1.5, 1.5);
[mapView setRegion: region];