Mapping data from RSS feed with no latitude/longitude using MapKit - iphone

Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However, I want to be able to display an annotation for a dynamic "incident" on the map. Here's where I'm having problems.
Basically my apps an RSS reader, and it downloads everything and saves each item of the feed (as in Story 1, Story 2) as currentItem. The data I want to grab and use to map the annotation can be found under currentItem.title - but I can't seem to get it to work in this tutorial's code or find the right place to put it.
The RSS feed I'm using doesn't have any latitude/longitude information either - making it even harder.
Any help would be great - I've been working on this for a couple of days now with still no luck.
UPDATE: I'm even considering launching the Google Maps application instead showing the annotation. But this in itself is raising issues. Below is the code I'm using but its throwing errors everywhere.
NSString *title = currentItem.title;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%1.6f,%1.6f&z=%d", title, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

In the end I just mapped the title using reverse lookup, and added the country afterwards so results would only be in the country where the address is. Not ideal, but it seems to work OK.

Related

How to bring the top bar in google maps in ios

I am developing an application in which i am opening goggle map in
webview with source and destination location but i am not able
to see the top bar which is displayed in the image attached.
http://i.stack.imgur.com/Yrwld.png
What i want is the top bar should also be displayed while opening map in iphone.
Kindly help.!In image it is showing the bar on the top.it is the default bar of google maps but i am not able get it .may i am not passing the correct url.the url i have given is :-
http://maps.google.com/?saddr=nagpur&daddr=pune&output=html
I am not clear about whether you are opening map in Safari or in same application using MapKit framework. But the top bar you are talking about will be displayed only if you open the map in Safari (as shown in code below), but if you are willing to have such control in your application map (ie using MapKit, MKMapView) you will have to code such control with same UI and functionality.
About the correct url for getting direction (in safari) see code:
NSString* url = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%#&daddr=%#",
[source stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[destination stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
];
//where source and destination will be your address strings.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

How to make link open "Maps" window when clicked

I would like to have a link in a web page in such a way that when the link is clicked it opens the standard "Maps" view in iPhone.
If such a thing is possible, what tag format do I need to use with the link?
It's pretty simple; you don't even need to use a specific scheme identifier. Any Google Maps URL will be opened with the Maps app automatically, as long as all the parameters are supported.
So links like these:
http://maps.google.com/maps?q=cupertino
http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino
Would automatically be opened in Maps. To find out more about what works and what doesn't see the Map Links page from the Apple URL Scheme Reference.
I used this code which works passing longitude lattitude:
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",cur_lat, cur_lon,[loc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"current %f %f",cur_lat,cur_lon);
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]];

iphone default map app open with different language

I successfully open Iphone default app with current user location but if user has selected a different language (e.g.. for Dutch Current Location = Aktueller Ort) then current location and route is totally wrong.
NSString *mystr=[[NSString alloc] initWithFormat:#"http://maps.google.com/maps?saddr=Current+Location&daddr=Destination"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
Although we can detect current language and match using switch case but we need to translate "Current Location" to all supported languages by iphone map app.
I tried wiki link for parameters and found hl parameter but not worked for me I think method for apply parameter by me is wrong or something.
So how can I open map app with particular fix language like english even when user selected different language?
thanx for any help!
You can get the current user location by the Core Location Framework and pass latitude and longitude to the google maps url. Or you can check the current language and translate "Current Location" in a lot of lang and pass it to the url.
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];

UIApplication OpenUrl double-escaping my URLs

Basically, i'm trying to program a "tweet this" button from inside my application. Depending on their spot in the application, they can click the tweet button and it'll shoot them out to Safari with a tweet message that changes depending on where they are.
In order to create URLs, I have to escape the query string that I want to put in the NSUrl object. So, I do this:
NSString* escapedTweet = [#"Some String With Spaces" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
After concatenating the base, my url comes out "http://www.twitter.com/home/?status=Some&20String%20With%20Spaces" - looked at it in the debugger and this is definitely the value (as expected). Now, I create my URL and launch safari:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escapedUrlString]];
But here's where the issue comes up: OpenUrl appears to be escaping my percent signs, so the actual URL that Safari goes to is "http://www.twitter.com/home/?status=Some%2520String%2520With%2520Spaces", which is obviously a problem since twitter creates the status message as "Some%20String%20With%20Spaces".
NSUrl will NOT allow me to create a URL with spaces in it, so i'm completely lost as to how to get my URLs to just include a %20. Has anyone else run into this issue or found a workaround?
I'm running on an iPad with an up to date OS, not sure if it's the same issue on the iPhone.
Edit: In a nutshell, how do I get openUrl to open http://www.twitter.com/home/?status=Some%20Url%20With%20Spaces without escaping my percent signs and creating a URL like http://www.twitter.com/home/?status=Some%2520Url%2520With%2520Spaces?
I am assuming that escapedUrlString is declared as NSURL *escapedUrlString = [NSURL URLWithString:escapedTweet];. Then your problem probably lies in openURL:[NSURL URLWithString:escapedUrlString]];, because you’re taking an URL, passing it into another URL and then opening it. Fix by passing in escapedURLString (which should be named ‘escapedURL’) instead of URLWithString:….

Load static google map into UIImageView?

I'm trying to show a small static google map in my app. I'm wondering if it's possible to do this using UIImageView? It doesn't seem to be working for me but maybe I'm doing something wrong.
This is what I have (I stripped the URL so that it's easier to read):
NSURL *mapurl = [[NSURL alloc] initWithString:#"http://maps.google.com/maps/api/staticmap?[...]"];
NSData *mapdata = [[NSData alloc] initWithContentsOfURL:mapurl];
UIImage *uimap = [[UIImage alloc] initWithData:mapdata];
self.map.image = uimap; // map is my UIImageView
[mapurl release];
[mapdata release];
[uimap release];
I know my UIImageView is setup correctly because if I replace the URL with one of an image then it loads fine. Also I know the google maps URL is correct because if I load it straight into a browser it shows up fine.
I'm starting to think that this might not be possible. If anyone has any ideas or alternatives please share.
Thanks.
Well I ended up finding a solution for this so I'll post it in case someone else runs into the same issue.
First I changed the way I load the image to using NSURLConnection. I don't think this particular change makes a difference but this is what allowed me to find the problem. When trying to load the URL I got a "bad url" error. So I did some searching on that and turns out there are some invalid characters in the google static map URL that must be escaped.
So basically just call this on the url and you should be good to go:
// The URL you want to load (snipped for readability)
NSString *mapurl = #"http://maps.google.com/maps/api/staticmap?[...]";
// Escape the string
mapurl = [mapurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
I haven't tested this solution with the code I have in my original post but I did test it with my new NSURLConnection implementation and it works perfectly. I assume it'll work fine with the code above as well since it was just a matter of escaping the string.