Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-09-2010, 03:40 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 25
HockeyHippo is on a distinguished road
Default MKCoordinateRegionMakeWithDistance Problem

So basically I'm trying to make two zoom functions, zoom in and zoom out.

I looked at the documentation and this is what I found:

Quote:
MKCoordinateRegionMakeWithDistance
Creates a new MKCoordinateRegion from the specified coordinate and distance values.

MKCoordinateRegion MKCoordinateRegionMakeWithDistance(
CLLocationCoordinate2D centerCoordinate,
CLLocationDistance latitudinalMeters,
CLLocationDistance longitudinalMeters
);
Parameters
centerCoordinate
The center point of the new coordinate region.
latitudinalMeters
The amount of north-to-south distance (measured in meters) to use for the span.
longitudinalMeters
The amount of east-to-west distance (measured in meters) to use for the span.
Return Value
A region with the specified values.

Availability
Available in iOS 3.0 and later.
Declared In
MKGeometry.h
So then I declared my two variables

Code:
	CLLocationDistance latitudinalMeters;
	latitudinalMeters = 200000;
	CLLocationDistance longitudinalMeters;
	longitudinalMeters = 200000;
And created these two functions:

Code:
-(IBAction) zoomOut: (MKMapView *) mapView: (CLLocationDistance *) latitudinalMeters: (CLLocationDistance *) longitudinalMeters{
	
	CLLocationCoordinate2D coordinate;
	coordinate.latitude =  mapView.userLocation.location.coordinate.latitude;
	coordinate.longitude = mapView.userLocation.location.coordinate.longitude;
	longitudinalMeters += 10000;
	latitudinalMeters += 10000;
	mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, latitudinalMeters, longitudinalMeters);


}

-(IBAction) zoomIn: (MKMapView *) mapView: (CLLocationDistance *) latitudinalMeters: (CLLocationDistance *) longitudinalMeters{
	
	CLLocationCoordinate2D coordinate;
	coordinate.latitude =  mapView.userLocation.location.coordinate.latitude;
	coordinate.longitude = mapView.userLocation.location.coordinate.longitude;
	longitudinalMeters -= 10000;
	latitudinalMeters -=  10000;
	mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, latitudinalMeters, longitudinalMeters);

}

But it keeps saying:

error: incompatible type for argument 2 of 'MKCoordinateRegionMakeWithDistance'

x4


Can I not use a variable here?
HockeyHippo is offline   Reply With Quote
Old 08-09-2010, 08:28 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by HockeyHippo View Post
So basically I'm trying to make two zoom functions, zoom in and zoom out.


<snip>
Can I not use a variable here?
Of course you can use a variable. The problem is that your methods are set up to take POINTERS to CLLocationDistance values as parameters. CLLocationDistance is a simple data type. You don't want the asterisks in the parameter types. Your method declarations should look like this:

Code:
-(IBAction) zoomOut: (MKMapView *) mapView: (CLLocationDistance) latitudinalMeters: (CLLocationDistance) longitudinalMeters
{
//code
}

-(IBAction) zoomIn: (MKMapView *) mapView: (CLLocationDistance) latitudinalMeters: (CLLocationDistance) longitudinalMeters
{
//code
}

Another problem with your code is that you are setting the initial span to 200 kilometers, which is pretty big, and then zooming in or out by 1 km for each click. Initially, that will make for a 0.5% change in zoom level. However, if you click "zoom out" enough times, the zoom level will go negative. Bad things will likely happen if you try to specify a negative zoom level.

If instead you zoom OUT over and over from 200 km, the 1KM you add each time will be a smaller and smaller change in total zoom level to the point where you won't even be able to see the change. Imagine a zoom change from 1000 km to 1001 km. Do you think you could even see it unless you were pixel peeking?

You should really be multiplying/dividing the previous latitudinalMeters/longitudinalMeters values by some constant like 1.1. Multiplying by 1.1 would make the map zoom out 10%, and dividing by 1.1. would make it zoom IN by 10%, no matter what the zoom level. That's what you want.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-10-2010, 08:44 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 25
HockeyHippo is on a distinguished road
Default

Thank you so much!

I know that the values I had were not very appropriate. To be honest those numbers are pretty random :P I just wanted to get it to build first before I spent the time to adjust the numbers to get them right.

Anyways, the pointer change made it work! Thanks so much!
HockeyHippo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
8 members and 316 guests
ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0