How to get a url for the current location in Mapkit?
I have a view controller which loads a map, I have set the current location as default when the map loads, the question I have is, how do I get a url for this location, so that I can store it in a nsstring and use it at some other place, to add it to tweet sheet basically.
You'll want to create an URL such as https://maps.google.com/maps??ll=55.123,12.234
Get the users coordinates from the MKMapView current users location
or if it's the current map center you are interested in
In practice it would look like this
CLLocationCoordinate2D myCoord = mapView.userLocation.coordinate; NSString *url = [NSString stringWithFormat:@"http://maps.google.com/?ll=%f,%f", myCoord.latitude, myCoord.longitude]; NSLog(@"The URL is: %@", url);
The snippet gives me the following output:
The URL is: http://maps.google.com/?ll=55.936699,12.289743
you must save the city and county in a string. then you can build a google link like this:
NSString *link = [NSString stringWithFormat: @"http://maps.google.com/maps?q=%@,%@",city,country"];