views:

45

answers:

3

i call the url of googlemaps to show a position to a given lat and long. How can i mark this position on the map with a pin ?

 NSString *latlong = [NSString stringWithFormat:@"%@,%@", einBetrieb.lat, einBetrieb.lng];
 NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?ll=%@",
      [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Regard Caglar

A: 

You should use MapKit to display map on iPhone, you will have greater flexibility and faster integration.

mapView being a MKMapView instance, you will have to manipulate your string to extract long and lat then

CLLocationCoordinate2D loc;
loc.latitude = extractedLatFromString;
loc.longitude = extractedLongFromString;
AddressAnnotation *pin = [[AddressAnnotation alloc] initWithCoordinate:loc];
[mapView addAnnotation:pin];

should do the job

VdesmedT
He isn't using MapKit.
logancautrell
thank you for the fast answer, i will try it now.
@logancautrell : He definitely should ;-) !
VdesmedT
+1  A: 

I think you really need to use the mapkit api to solve your problems. Launching the Maps App externally will not give you the access you desire

you can do a quick search of StackOverFlow to find solutions, here is the first one I found

http://stackoverflow.com/questions/1873755/iphone-mapkit-update-annotations-coordinates-and-map

Aaron Saunders
A: 

Try this url:

NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?q=%@", [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

That should get you what you want. Replace the "ll" with a "q"

Geoff Baum
you guys are very fast and helpful. @all: thank you very much