hussain
hussain

Reputation: 810

How to create url/link of a Location in Google Map which can be share to anyone using swift?

I have plotted a marker in a Google Map, now i want to share that location to my friends via url/link. how to create link of that location in swift. The use of this is if my friends click on that url/link, it will take to that location in a Google Map. I dont have any idea about it. the below code shows how i created a marker:

            let position = CLLocationCoordinate2DMake(latitude,longitude)

            let location = GMSMarker(position: position)
            location.icon = image
            location.icon = self.imageWithImage(image, scaledToSize: CGSize(width: 30.0, height: 30.0))
            location.title = "the photo is clicked here"
            location.map = MapView 

Upvotes: 0

Views: 860

Answers (1)

LifeForce
LifeForce

Reputation: 41

To launch Apple Maps or Google Maps you need to create an NSURL.

let targetURL = NSURL(string: "http://maps.apple.com/?q=FartCity")!

https://developers.google.com/maps/documentation/ios-sdk/urlscheme

let targetURL = NSURL(string: "comgooglemaps://?q=FartCity")!

Check that the user has the correct map app by checking if the url can be handled.

let isAvailable = UIApplication.sharedApplication().canOpenURL(targetURL)

open the url

UIApplication.sharedApplication().openURL(targetURL) 

Upvotes: 3

Related Questions