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-16-2010, 05:17 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: MA
Posts: 126
nd049 is on a distinguished road
Default Getting Current Location

Hi Everyone,

I am trying to make my app open the Maps app and display directions from the users current location to an address. I was looking at a tutorial online but when I tried its code I keep getting errors. What I have for my code is:

Code:
- (IBAction) openMap: (id) sender {
	
	 CLLocationCoordinate2D myLocation = [self getCurrentLocation];
	 NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",myLocation.latitude, myLocation.longitude,[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
	 [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
When compile this though im getting "Invalid Initializer" for the CLLocationCoordinate2D line. According to the tutorial I read people were saying that it worked perfectly... so I'm not sure what I am doing wrong. If anyone could help out I would appreciate it a lot!
nd049 is offline   Reply With Quote
Old 08-16-2010, 05:31 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 nd049 View Post
Hi Everyone,

I am trying to make my app open the Maps app and display directions from the users current location to an address. I was looking at a tutorial online but when I tried its code I keep getting errors. What I have for my code is:

Code:
- (IBAction) openMap: (id) sender {
	
	 CLLocationCoordinate2D myLocation = [self getCurrentLocation];
	 NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",myLocation.latitude, myLocation.longitude,[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
	 [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
When compile this though im getting "Invalid Initializer" for the CLLocationCoordinate2D line. According to the tutorial I read people were saying that it worked perfectly... so I'm not sure what I am doing wrong. If anyone could help out I would appreciate it a lot!
The line you've shown:

Code:
	 CLLocationCoordinate2D myLocation = [self getCurrentLocation];
implies that your class includes a method "getCurrentLocation". There's no system method by that name, and you are sending the message to self, so you would need to write a routine with that name that returns a CLLocationCoordinate2D.

There really isn't a single call to get your current location. You have to create a CLLocationManager object, configure it, and ask it to start updating your location. Part of configuring the CLLocationManager is to set up some object (usually self) to be it's delegate. Once you've done that, it calls the delegate when it has updated location information to report. You can send the location information you get back to Google maps.

Take a look at the "LocateMe" app (there's a link to it in the XCode docs in the section on CLLocationManager, under the heading "related sample code". That includes a good example of getting GPS locations.

By the way, what is the "address" parameter in the line that builds your URL? Is that supposed to be a street address? You have to issue a special reverse DNS lookup call on a GPS location and wait for a reply before you can get a street address from a GPS location. The street address is not provided automatically.
__________________
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
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: 354
4 members and 350 guests
givensur, linkmx, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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