Search code examples
iosswiftgoogle-mapscocoa-touchgoogle-maps-sdk-ios

Send to google maps and add a marker by URL


I have a button in my app thats sends the user to Google's maps app (Google Maps) like that:

let urlString = String(format: "comgooglemaps://?center=%f,%f&zoom=14",self.coordinates.latitude, self.coordinates.longitude)
UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)

(For non-iOS developers: the URL I send the user to is comgooglemaps://?center=myLat,myLong&zoom=14)

it works but the problem is that there is no marker on the location, what url should I send the user in order to show a marker there?

Thanks!


Solution

  • You can send the latitude and longitude as search parameters. This will place a marker on the location.

    let urlString = String(format: "comgooglemaps://?q=%f,%f&center=%f,%f&zoom=14",self.coordinates.latitude, self.coordinates.longitude, self.coordinates.latitude, self.coordinates.longitude)
    UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)