Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 12-21-2008, 12:33 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Germany, Munich
Posts: 230
Default Opening the maps app with a given route/direction

Hi,

i am trying to start the maps app with a given route (the direction/way should be drawn and visible):

Code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"maps://maps.google.com/maps?saddr=48.09292914584927,11.76961898803711&daddr=48.09503592181566,11.76950097084045&z=17"]];
The zoom is ok and the destination address is visible in the right textbox. But the source adress is still empty. Am i missing something (wrong parameter name or direction)?

Cheers
Ralf
rhuettl is offline   Reply With Quote
Old 12-21-2008, 01:50 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Germany, Munich
Posts: 230
Default

It seems that the second URL-Parameter (here daddr) will be ignored so maybe this is a syntax problem.

With the google maps web version the query is working very fine!

Ralf

Last edited by rhuettl; 12-21-2008 at 01:56 PM.
rhuettl is offline   Reply With Quote
Old 12-21-2008, 03:07 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,575
Default use http instead of maps

This seems to work in os 2.2 if you use "http://" instead of "maps://". Try this.

Code:
NSString *urlString = @"http://maps.google.com/maps?daddr=37.74324,-121.43432&saddr=37.5,-121.4";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];
More info on params here:
objective-d » Blog Archive » Launching the iPhone maps application from your own code

Official list of params here:
Google Map Parameters - Google Mapki

Apple URL reference here:
https://developer.apple.com/iphone/l...roduction.html
__________________
smasher is offline   Reply With Quote
Old 01-17-2009, 08:23 AM   #4 (permalink)
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 254
Send a message via Skype™ to Jume
Default

Does anyone knows how to use maps URL scheme for driving directions from current location?

I tried by using "Current Location" as a source "saddr" quesry string but it does not recognize it as Current Location bookmark in Maps app. Anyone successfully done this?

this dosn't work
Code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.google.com/maps?daddr=Paris,+France&saddr=Current+Location"]];

Last edited by Jume; 01-17-2009 at 10:14 AM.
Jume is offline   Reply With Quote
Old 01-17-2009, 12:05 PM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,575
Default

Quote:
Originally Posted by Jume View Post
Does anyone knows how to use maps URL scheme for driving directions from current location?

I tried by using "Current Location" as a source "saddr" quesry string but it does not recognize it as Current Location bookmark in Maps app. Anyone successfully done this?
Last time I researched this, it seemed you needed to get the current location from Core Location, and pass those lat/long in as the source address. There's no param in the map API for "current location."
__________________
smasher is offline   Reply With Quote
Old 01-17-2009, 05:55 PM   #6 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 501
Default

Quote:
Originally Posted by Jume View Post
Does anyone knows how to use maps URL scheme for driving directions from current location?
Did you ever figure this out?

I've been able to get current location using the Apple LocateMe example. I've also been able to formulate a search for businesses near a specific lat/long via a URL passed to Google maps.

What I haven't figured out is:
1. How to pass the current location found to the source address
2. If multiple business results are found, let the user pick one that become the destination address for driving directions.
DenVog is offline   Reply With Quote
Old 04-23-2009, 12:39 AM   #7 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 28
Default

Quote:
Originally Posted by rhuettl View Post
It seems that the second URL-Parameter (here daddr) will be ignored so maybe this is a syntax problem.
hi rhuetti. i had the same problem. it turns out, indeed, that this has to do with the number or ordering of url parameters. i solved the problem by adding an extra "dummy" parameter at the beginning. really strange, but works!

Code:
href="maps://maps.google.com/maps?xyz=xyz&saddr=$lat,$lng&daddr=$iPhoneEndAddress"
hope this helps. on another note, i think you would use "http://" rather than "maps:" since your launching from within your app. mine happens to be a web link.
--brian
bpgillett is offline   Reply With Quote
Old 05-31-2009, 07:45 PM   #8 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 16
Question Embedding

How about if I want to embed the route in my application.

Lets say Im build a "take me there" application, where you give a lat,lon and the app draws you the route.

I will put a UIWebView in my View and load a url, right?

How will that URL look?

Is there any pitfall I might be overlooking?

Thanks in advance
Gonso
gonso75 is offline   Reply With Quote
Old 06-02-2009, 05:57 PM   #9 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 28
Default

Quote:
Originally Posted by gonso75 View Post
How about if I want to embed the route in my application. -Gonso
if you want to embed the route in your application, you should use the 3.0 sdk. it would be very slow to pull it off with a web based map loaded into a webview.
bpgillett is offline   Reply With Quote
Old 06-08-2009, 04:35 AM   #10 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default Opening the maps app with a given route/direction

You can do this by obtaining the latitude and longitude from CoreLocation, and then passing that into the maps URL. You can mix and match lat/lon and street addresses, which is what I do:

Code:
        CLLocationCoordinate2D currentLocation = [self getCurrentLocation];
        NSString* address = @"123 Main St., New York, NY, 10001";
        NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",
                         currentLocation.latitude, currentLocation.longitude,
                         [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
This works on my iPhone (2.2.1), and I didn't need to add any dummy parameters to the URL. Just saddr (lat/lon) and daddr (address).
n8r0n is offline   Reply With Quote
Old 06-08-2009, 08:10 AM   #11 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 28
Default

Quote:
Originally Posted by n8r0n View Post
You can do this by obtaining the latitude and longitude from CoreLocation, and then passing that into the maps URL.
this will work, but it will close your app completely and open the iphone maps app instead to display the route. if you want to use the iphone map within your app, you'll need to use the 3.0 sdk.
bpgillett is offline   Reply With Quote
Old 06-08-2009, 07:51 PM   #12 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default Opening the maps app with a given route/direction

Quote:
Originally Posted by bpgillett View Post
this will work, but it will close your app completely and open the iphone maps app instead to display the route. if you want to use the iphone map within your app, you'll need to use the 3.0 sdk.
That was the intent of the original post (see topic title). Using Maps does close your app. I was merely replying to the original poster, and Jume, that this worked for me on OS 2.2.1 (with specific code snippet).
n8r0n is offline   Reply With Quote
Old 06-12-2009, 03:34 AM   #13 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 32
Default

So is there any official way to show route/direction with 3.0 MapKit? I looked around the class references but didn't find anything useful. Apparently you need to draw the route yourself.

Given 2 points (destination / source), is there any way to retrieve the coordinates of the intermediate points in the route?
mesohorny is offline   Reply With Quote
Old 06-12-2009, 03:41 PM   #14 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default

Quote:
Originally Posted by mesohorny View Post
So is there any official way to show route/direction with 3.0 MapKit? I looked around the class references but didn't find anything useful. Apparently you need to draw the route yourself.

Given 2 points (destination / source), is there any way to retrieve the coordinates of the intermediate points in the route?
Im at the same situation.

Ive found this: The Reluctant Blogger :: Drawing polyines or routes on a MKMapView (Using Map Kit on the iPhone)

But, where i can get this lat long about the route?

thks
bixcoito is offline   Reply With Quote
Old 09-16-2009, 05:41 AM   #15 (permalink)
baj
Registered Member
 
Join Date: Jul 2009
Posts: 12
Default

Hi did you find the solution? I am also searching for the same.

Thanks
baj is offline   Reply With Quote
Old 09-16-2009, 08:17 AM   #16 (permalink)
Registered Member
 
cmezak's Avatar
 
Join Date: Jul 2008
Posts: 193
Default

Bump! I have a feeling that there is no solution for this, but I would love it if route-finding is part of the mapkit API. Perhaps there's a way to get the route via the google API and then display it in mapkit using the technique in the link above?

- Charlie
cmezak is offline   Reply With Quote
Old 10-04-2009, 05:29 PM   #17 (permalink)
Registered Member
 
cmezak's Avatar
 
Join Date: Jul 2008
Posts: 193
Default

Using the technique from the above link, I've been able to draw a route in my MKMapView. However, it's taking quite a while to draw an redraw the route whenever the map is moved. I'm thinking that it might be better to just open the route in the maps app.

But, my route comes from a KML file as a series of gps coordinates. Is there a way to encode them into the URL that I use to open the maps app so that they appear as a route when the maps app opens?

- Charlie
cmezak is offline   Reply With Quote
Old 10-08-2009, 09:47 AM   #18 (permalink)
Senior member
iPhone Dev SDK Supporter
 
Join Date: May 2009
Location: Lille, France
Posts: 32
Default some more

Hi

I have the same need
Is their something new ? I need to show the map with direction from actual position to known address ...

thanks

greg
Gregoire is offline   Reply With Quote
Old 10-08-2009, 06:15 PM   #19 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 107
Default

Quote:
Originally Posted by iKomobi View Post
Hi

I have the same need
Is their something new ? I need to show the map with direction from actual position to known address ...

thanks

greg
Initialize corelocation, make sure you have the latitude and longitude of your current position, send it to the google maps app and it will open with the given route.
stuffradio is offline   Reply With Quote
Old 10-27-2009, 05:20 AM   #20 (permalink)
Senior member
iPhone Dev SDK Supporter
 
Join Date: May 2009
Location: Lille, France
Posts: 32
Default different behavior simulator / device

Quote:
Originally Posted by stuffradio View Post
Initialize corelocation, make sure you have the latitude and longitude of your current position, send it to the google maps app and it will open with the given route.
thanks for your tips

I waste some time on it so just this information : the behavior is different on device and on simulator, I tested on 3.1.2. The map and information window is showned differently

greg
Gregoire is offline   Reply With Quote
Old 12-15-2009, 10:50 PM   #21 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default

Quote:
Originally Posted by Gregoire View Post
thanks for your tips

I waste some time on it so just this information : the behavior is different on device and on simulator, I tested on 3.1.2. The map and information window is showned differently

greg
There is no Maps app in the simulator, so the simulator has to open Safari, pointing at google maps. The Apple documentation for the Maps URL scheme mentions this:

iPhone Dev Center: Apple URL Scheme Reference: Map Links
n8r0n is offline   Reply With Quote
Old 12-16-2009, 11:40 PM   #22 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 1
Default Using this code in an iPhone optimized webpage

I am hoping to be able to implement the Core Location solution in my iPhone optimized web page so that paramedics can click on a link next to a hospital's name and get directions in Google Maps from their current location. How would I incorporate this as Javascript into the HTML; either inline or as part of an external javascript file?

Assistance on this would be greatly appreciated! The paramedics of Alameda County would be very thankful!!!!

-joshua the lorax

Test site link here
lorax is offline   Reply With Quote
Old 12-17-2009, 03:00 AM   #23 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default

Quote:
Originally Posted by lorax View Post
I am hoping to be able to implement the Core Location solution in my iPhone optimized web page so that paramedics can click on a link next to a hospital's name and get directions in Google Maps from their current location. How would I incorporate this as Javascript into the HTML; either inline or as part of an external javascript file?

Assistance on this would be greatly appreciated! The paramedics of Alameda County would be very thankful!!!!

-joshua the lorax

Test site link here
Joshua,

I don't know if you can directly get the current location from the phone in a dynamic web page. See discussion here:

iPhone app that access the Core Location framework over web - Stack Overflow

or

Accessing the iPhone Location from a Webpage [splitbrain.org]

That's one advantage of the SDK. It gives you access to stuff like that. But, if you can get the current location (using one of the two techniques linked to above, or some other way), then you can use a web page like this:

Code:
<html>
  <head>
    <meta name="viewport" content="width=320"/>
    <script language="javascript" type="text/javascript">
      <!--
      function mapTo(address) {
	// put something more sophisticated here, if you don't want to hard-code the start coordinates:
	window.open('http://maps.google.com/maps?saddr=47.58012312,-122.3459&daddr=' + address);
      } 
      -->
    </script>
  </head>
  <body>
     Click on <a href="http://maps.google.com/maps?saddr=47.57164,-122.4096&daddr=4916+Erskine+Way+SW,+Seattle,+WA,+98116"> this link</a> to open the Maps app.
     <br/>
     Or click on <a href="#" onClick="javascript:mapTo('5040+Erskine+Way+SW,+Seattle,+WA,+98116');return false" >a more dynamic map link here</a>.
  </body>
</html>
I put this page on my webserver, and tested it with my iPhone. Does this help?
n8r0n is offline   Reply With Quote
Old 12-17-2009, 03:11 AM   #24 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
Default Using this code in an iPhone optimized webpage

Joshua,

here's a couple more links regarding a way to get the phone's current location with your javascript function.

Geolocation API on the iPhone - Stack Overflow

it looks like iPhone might now (3.0) support this without 3rd-party apps or javascript libraries:


Safari Dev Center: Safari Web Content Guide: Getting Geographic Locations
n8r0n 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,308
Threads: 39,107
Posts: 171,455
Top Poster: smasher (2,575)
Welcome to our newest member, howardie08
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0