Using Maps & Geographic Locations / Implementing the Map It Button
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
We've done Get My Location. Now, let's implement Map It and we want an onClick handler which I'm going to call Map It. There we go. No typos and now, what I want to do is I want to implement a line of code and I'll show you what I want to eventually implement. I want something that will say Window Open, HTTP, Maps, Google, Thumb Maps and then these are the parameters that we need and what we're going to have is location equal latitude, longitude and thats the code that we're going to want to be generated and this is the URL that we want and what you can do in the documentation, either the Google Maps documentation or in the iPhone Scheme documentation, you can find the various parameters that you can use for this call and we'll be looking at several of the other ones that you can use but, this is the basic URL that you want to construct. Now, Latitude and Longitude are variables that contain numbers and I do not want this text string over here and this is the way in which I usually enter this type of URL. I construct the URL in its general form and now, what I'm going to do is I'm going to build it. I take in the first part of the URL and I want to add to that string Latitude. This is, mind you, the value of that variable plus and I want now the comma as a string and I want to concatenate it with the value of Longitude and this should be constructing the correct URL and what I'm going to do is now to test this. I'll run it in the Simulator but the window will probably not open because the Simulator doesn't go quite that far in most cases but let's save it and see what happens when we run it. Now, remember I'm not saving the location from one execution to the next so I've got to start by getting the location and again, I have to give permission to pick up the location and now, I can come to Map It and it's not able to get to that URL but don't worry about that because it doesn't work on Simulator. If you now move this so we could stop here onto your iPhone, which we'll do in a moment, you will see that it does indeed work and if you want to be absolutely certain, take this code here, copy it and put it into that text field and so now, we can run it and we should have, I think, a decent value. Let's run it here Ñ Get My Location, Give Permission Ñ for the iPhone to pick up the location and then map it and the mapping won't work but if you come back here and look in that text field, we should be seeing that we have indeed constructed a valid URL and if you want, you can copy it out of here and paste it into a browser and you will see that you are constructing a decent URL so now, we're OK. We can stop this. We come here and to run and share and you can install it. You can do what we've done before which is save it to disk or if you have a MobileMe account, you can put it on your MobileMe server, but all I'll do here is save it and then move it up to my web server and from there, execute it from the iPhone and you will see that it works. That what's happened here is Ñ as I said it's a little difficult to demonstrate Geolocation, but that's made up for by the fact that it is so easy to implement it. This is the entire code that I've used for Geolocation. This is the getPosition button. This is the callback routine and this is the code that produces the map. It's as simple as that. I can comment out this line because that is just for debugging and you can see there's just about 5 lines of code to enable you to add Geolocation to your iPhone web app.
Tutorial Information
| Course: | Developing iPhone Web Apps |
| Author: | Jesse Feiler |
| SKU: | 34075 |
| ISBN: | 1-935320-89-0 |
| Release Date: | 2009-12-31 |
| Duration: | 8 hrs / 103 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 