iOS - Segue issue while using GoogleMaps SDK - ios

I am facing a weird issue while using GoogleMapsSDK. On my view that is showing the Google Map, a navigation controller is embedded. On the nav bar, I have a bar button that I have connected to a new view. When the button is pressed, the segue is laggy and doesn't show any content.
Here is what is happening: http://gph.is/2putLtQ
Not sure what the issue is. I have the same set up working without GoogleMapsSDK implemented.
Here is the GoogleMaps view controller:
import UIKit
import GoogleMaps
class GoogleMapsViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
var locationManager = CLLocationManager()
var tacoLocations = [TacoLocation]()
var tacoLocationPlace_id :String!
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
let lat = self.locationManager.location?.coordinate.latitude
let lng = self.locationManager.location?.coordinate.longitude
// creates the map and zooms the current user location, at a 15.0 zoom
let camera = GMSCameraPosition.camera(withLatitude: lat!, longitude: lng!, zoom: 15.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
for location in self.tacoLocations {
let marker = GMSMarker()
let lat = location.locationLat
let lng = location.locationLng
marker.position = CLLocationCoordinate2D(latitude: lat!, longitude: lng!)
marker.title = location.name
if location.open_now == false {
marker.snippet = "\(location.vicinity!)\nClosed"
} else if location.open_now == true {
marker.snippet = "\(location.vicinity!)\nOpen"
} else {
}
marker.userData = location
marker.icon = UIImage(named: "taco_marker.png")
marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0.2)
marker.map = mapView
}
// enable my location dot
mapView.isMyLocationEnabled = true
mapView.delegate = self
}
//MARK: GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let customWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?.first as! CustomInfoWindow
customWindow.nameLabel.text = marker.title
customWindow.addressLabel.text = marker.snippet
return customWindow
}
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
let tacoLocation = marker.userData as! TacoLocation
self.tacoLocationPlace_id = tacoLocation.place_id
DispatchQueue.main.async {
self.performSegue(withIdentifier: "MoreInfoSegue", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MoreInfoSegue" {
let tabVC = segue.destination as! UITabBarController
let moreInfoVC = tabVC.viewControllers?[0] as! MoreInfoViewController
let reviewVC = tabVC.viewControllers?[1] as! ReviewViewController
moreInfoVC.tacoLocationPlace_id = self.tacoLocationPlace_id
reviewVC.tacoLocationPlace_id = self.tacoLocationPlace_id
} else if segue.identifier == "ARSegue" {
//segue to new view that is not working correctly.
}
}
}
The only thing in the second view controller is the viewdidload.
Any help is much appreciated!

I uninstalled the google maps pods and then reinstalled them. That fixed my issue. Must have been a bug with xcode.

Related

Embed UINavigationController into MapKit programatically (in Swift) to hold UISearchController

I'm trying to add a search bar to my map programatically, and have established that I need to add a navigation controller to my map view in order to format the search bar correctly at the top of the view. I have come to the conclusion I actually need a UISearchController, rather than a UI SearchBar. However, I do not have a navigation controller coded into the app from the AppDelegate file because I am also using a tabBarController, which is coded in the app delegate.
Basically, I'm looking for a way to embed a UINavigationController into my map view programatically so I can add the UISearchController to the NavigationController.
The ultimate goal is to create a map with a search feature to allow users to search for locations - if anyone has other suggestions of how I can accomplish this goal within the framework I already have it would be much appreciated!
My AppDelegate and map view code are below.
AppDelegate
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
return true
}
}
MapViewController
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var mapVw: MKMapView!
let locationManager = CLLocationManager()
var regionHasBeenCentered = false
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
if !regionHasBeenCentered {
let span: MKCoordinateSpan = MKCoordinateSpanMake(0.5, 0.5)
let userLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(userLocation, span)
mapVw.setRegion(region, animated: true)
regionHasBeenCentered = true
}
self.mapVw.showsUserLocation = true
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
setupMapView()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func setupMapView() {
mapVw = MKMapView()
mapVw.delegate = self
let leftMargin:CGFloat = 0
let topMargin:CGFloat = 0
let mapWidth:CGFloat = view.frame.size.width
let mapHeight:CGFloat = view.frame.size.height
mapVw.frame = CGRect(x: leftMargin, y: topMargin, width: mapWidth, height: mapHeight)
let noLocation = self.mapVw.userLocation.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.05, 0.05)
let pinLocation = MKCoordinateRegionMake(noLocation, span)
mapVw.setRegion(pinLocation, animated: true)
print(pinLocation)
print(noLocation)
//setup long press gesture
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(self.addAnnotation(_:)))
self.mapVw.addGestureRecognizer(longPress)
view.addSubview(mapVw)
}
#objc func addAnnotation(_ gestureRecognizer:UIGestureRecognizer) {
if gestureRecognizer.state != UIGestureRecognizerState.began {
return
}
let touchPoint = gestureRecognizer.location(in: self.mapVw)
let newCoordinates = self.mapVw.convert(touchPoint, toCoordinateFrom: self.mapVw)
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinates
annotation.title = "Virtual Location"
annotation.subtitle = "Dropped Pin"
self.mapVw.removeAnnotations(mapVw.annotations)//remove previous pin
self.mapVw.removeAnnotation(annotation)
//create circle attributes
let cent = newCoordinates
let rad: Double = 500 //adjust radius to make circle bigger.
let circle = MKCircle(center: cent, radius: rad)
self.mapVw.addAnnotation(annotation)
self.mapVw.removeOverlays(self.mapVw.overlays)//remove previous circle
self.mapVw.add(circle)
print(newCoordinates)
print(circle)
}
//circle overlay function
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay.isKind(of: MKCircle.self){
let circleRenderer = MKCircleRenderer(overlay: overlay)
circleRenderer.fillColor = UIColor.blue.withAlphaComponent(0.05)
circleRenderer.strokeColor = UIColor.blue
circleRenderer.lineWidth = 0.5
return circleRenderer
}
self.mapVw.removeOverlays(overlay as! [MKCircle])
print(overlay)
return MKOverlayRenderer(overlay: overlay)
}
}
TabBarController
import UIKit
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let messagesController = MessagesController()
let messagesNavController = UINavigationController(rootViewController: MessagesController())
messagesNavController.tabBarItem.title = "Messages"
let postsVC = PostsViewController()
postsVC.tabBarItem.title = "Posts"
let organiserVC = OrganiserViewController()
organiserVC.tabBarItem.title = "Organiser"
let mapVC = MapViewController()
mapVC.tabBarItem.title = "Map"
let mapNavigationController = UINavigationController(rootViewController: mapVC)
viewControllers = [messagesNavController, postsVC, organiserVC, mapVC]
}
}

Custom Marker in Google Map in swift

I'm trying to show my custom view on click of pin in google map. I have mad my custom view for it in xib file and call that file in the delegate method of func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { But when i run the app and tap the marker it does not show my view. How can i show this? This is my code for custom Xib file,
class MapMarkerWindow: UIView {
#IBOutlet weak var saloonImage: UIImageView!
#IBOutlet weak var nameLbl: UILabel!
#IBOutlet weak var addressLbl: UILabel!
#IBOutlet weak var descriptionLbl: UILabel!
var spotData: NSDictionary?
class func instanceFromNib() -> UIView {
return UINib(nibName: "MapMarkerWindowView", bundle: nil).instantiate(withOwner: self, options: nil).first as! UIView
}
}
This is the code in my VC where i'm showing my map,
#IBOutlet weak var customView: UIView!
var mapView : GMSMapView?
var locationManager = CLLocationManager()
private var infoWindow = MapMarkerWindow()
fileprivate var locationMarker : GMSMarker? = GMSMarker()
override func viewDidLoad() {
super.viewDidLoad()
self.infoWindow = loadNiB()
GMSServices.provideAPIKey("AIzaSyBMppjEPlRBHUD4To2KqNLgmhu1QcxHg3g")
let camera = GMSCameraPosition.camera(withLatitude: 31.516331, longitude: 74.342792, zoom: 6)
mapView = GMSMapView.map(withFrame: .zero, camera: camera)
view = mapView
let states = [
State(name: "Hafeez Center", long: 74.342792, lat: 31.516331, snippets: "Lahore"),
State(name: "Kalma Chowk", long: 74.331553, lat: 31.504532, snippets: "Lahore"),
// the other 51 states here...
]
for state in states {
let state_marker = GMSMarker()
state_marker.position = CLLocationCoordinate2D(latitude: state.lat, longitude: state.long)
state_marker.title = state.name
state_marker.snippet = "Hey, this is \(state.snippets)"
state_marker.map = mapView
}
self.mapView?.isMyLocationEnabled = true
//Location Manager code to fetch current location
self.locationManager.delegate = self
self.locationManager.startUpdatingLocation()
}
func loadNiB() -> MapMarkerWindow {
let infoWindow = MapMarkerWindow.instanceFromNib() as! MapMarkerWindow
return infoWindow
}
//Location Manager delegates
private func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0)
self.mapView?.animate(to: camera)
//Finally stop updating location otherwise it will come again and again in this delegate
self.locationManager.stopUpdatingLocation()
}
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
var markerData : NSDictionary?
if let data = marker.userData! as? NSDictionary {
markerData = data
}
locationMarker = marker
infoWindow.removeFromSuperview()
infoWindow = loadNiB()
guard let location = locationMarker?.position else {
print("locationMarker is nil")
return false
}
// Pass the spot data to the info window, and set its delegate to self
infoWindow.spotData = markerData
//infoWindow.delegate = self
// Configure UI properties of info window
infoWindow.alpha = 0.9
infoWindow.layer.cornerRadius = 12
infoWindow.layer.borderWidth = 2
//infoWindow.infoButton.layer.cornerRadius = infoWindow.infoButton.frame.height / 2
let saloonImage = markerData!["image"]!
let name = markerData!["name"]!
let address = markerData!["address"]!
let description = markerData!["description"]!
infoWindow.addressLbl.text = address as? String
infoWindow.nameLbl.text = name as? String
infoWindow.descriptionLbl.text = description as? String
infoWindow.saloonImage.image = saloonImage as? UIImage
//Offset the info window to be directly above the tapped marker
infoWindow.center = mapView.projection.point(for: location)
infoWindow.center.y = infoWindow.center.y - 82
self.view.addSubview(infoWindow)
return false
}
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if (locationMarker != nil){
guard let location = locationMarker?.position else {
print("locationMarker is nil")
return
}
infoWindow.center = mapView.projection.point(for: location)
infoWindow.center.y = infoWindow.center.y - 82
}
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
infoWindow.removeFromSuperview()
}
This is how my pin looks when i tap on it.
From your code it seems that there is a problem in loading Nib.
Please check below code.
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
self.tappedmarker = marker
var point = mapView.projection.point(for: marker.position)
point.y = point.y - 110
let camera = mapView.projection.coordinate(for: point)
let position = GMSCameraUpdate.setTarget(camera)
mapView.animate(with: position)
self.customMarker = CustomMarker.instancefromNib() as! CustomMarker
customMarker.layer.cornerRadius = 10.0
customMarker.clipsToBounds = true
self.customMarker.center = mapView.projection.point(for: marker.position)
self.customMarker.center.y = self.customMarker.center.y - 110
self.view.addSubview(self.customMarker)
self.customMarker.bringSubview(toFront: self.view)
return true
}
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if (tappedmarker != nil) {
guard let location = tappedmarker?.position else {
print("locationMarker is nil")
return
}
customMarker.center = mapView.projection.point(for: location)
customMarker.center.y = customMarker.center.y - 100
}
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
if self.view.subviews .contains(self.customMarker) {
self.customMarker.removeFromSuperview()
return
}
}
Here is the instancefromNib :
class CustomMarker: UIView {
#IBOutlet weak var lblTitle: UILabel!
class func instancefromNib() -> UIView {
return UINib.init(nibName: "CustomMarker", bundle: nil).instantiate(withOwner: self, options: nil).first as! UIView
}
}
This will look like this :
Hope this will help!
Just set your mapView delegate in viewDidLoad()
self.mapView.delegate = self

Google maps change mapType on segmented control click

Here is the problem. In my view controller, I have placed a segmented control on the top.
On controller load it displays the map, circle and the marker. Now, when I click the segmented control to change the map type it goes into the code block on select but never updates the Map type.
Please see the code here.
class MapController: UIViewController, CLLocationManagerDelegate , GMSMapViewDelegate {
var locationManager:CLLocationManager!
let marker = GMSMarker()
var roundCircle: GMSCircle!
var mapView = GMSMapView()
private var didPerformGeocode = false
enum maptype:NSInteger
{
case standardmap = 0
case satellitemap = 1
}
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func segmentedControlAction(_ sender: UISegmentedControl)
{
switch sender.selectedSegmentIndex {
case maptype.standardmap.rawValue:
mapView.mapType = .normal
**no change in the map type**
case maptype.satellitemap.rawValue:
mapView.mapType = .satellite
**no change in the map type**
default:
break
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
determineMyCurrentLocation()
}
func determineMyCurrentLocation() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
guard !didPerformGeocode else { return }
didPerformGeocode = true
locationManager.stopUpdatingLocation()
let camera = GMSCameraPosition.camera(withLatitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude, zoom: 13.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
self.view = mapView
let markerImage = UIImage(named: "mapMarker")!.withRenderingMode(.alwaysTemplate)
let markerView = UIImageView(image: markerImage)
markerView.tintColor = UIColor.red
marker.iconView = markerView
marker.position = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
marker.map = mapView
roundCircle = GMSCircle(position: camera.target, radius: 1500) //0.96 Miles
roundCircle.fillColor = UIColor.red.withAlphaComponent(0.3)
roundCircle.strokeColor = nil
roundCircle.map = mapView
}
}
Honestly, I don't use Google Maps
However, to change MapTypes in Apple Maps I use
#IBAction func Whatever(_ sender: UISegmentedControl) {
mapView.mapType = MKMapType.init(rawValue: UInt(sender.selectedSegmentIndex)) ?? .normal
}
Maybe it will work

How do I add a marker when I press the done button?

Okay, so I want to add a marker when I click the done button. I want to add my current locations marker to the MapVC class when I click the done button in AddPinPointVC. What would I have to do to do this?
Here's the relevant code:
MapsVC
class MapsVC: UIViewController {
weak var googleMaps: GMSMapView!
var locationManager = CLLocationManager()
var currentLocation: CLLocation?
var placesClient: GMSPlacesClient!
var zoomLevel: Float = 15.0
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 39.9533, longitude: -75.1593, zoom: 15.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
self.view = mapView
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = 50
locationManager.startUpdatingLocation()
locationManager.delegate = self as? CLLocationManagerDelegate
placesClient = GMSPlacesClient.shared()
if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){
currentLocation = locationManager.location
}
}
static var latitude: CLLocationDegrees?
}
AddPinPointVC
class AddPinPointVC: UIViewController, UICollectionViewDelegateFlowLayout,UIPickerViewDelegate, UIPickerViewDataSource {
var pickerdata: [String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleCancel))
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(handleCancel))
//function for cancel button
func handleCancel() { dismiss(animated: true, completion: nil) }
func handleDone(){
dismiss(animated: true, completion: nil)
let userMarker = GMSMarker()
userMarker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees, longitude: CLLocationDegrees)
// userMarker.title = typeOfPlaces[row]
userMarker.snippet = ""
}
}
If there are any further questions, please let me know! Thank you.
You should make a delegate for this with a function that fires when the Done button is pressed.
Protocol
protocol AddPinPointDelegate: class {
func addPinPointWillDismiss(_ marker: GMSMarker)
}
MapsVC
class MapsVC: UIViewController, AddPinPointDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 39.9533, longitude: -75.1593, zoom: 15.0)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
[...]
}
[...]
var mapView: GMSMapView!
//assuming you open AddPinPointVC via a segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "presentAddPinPoint" { //the identifier you gave for the segue
(segue.destination as! AddPinPointVC).delegate = self
}
}
func addPinPointWillDismiss(_ marker: GMSMarker) {
marker.map = mapView
}
}
AddPinPointVC
class AddPinPointVC: UIViewController, UICollectionViewDelegateFlowLayout, UIPickerViewDelegate, UIPickerViewDataSource {
[...]
weak var delegate: AddPinPointDelegate?
func handleDone() {
let userMarker = GMSMarker()
userMarker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees, longitude: CLLocationDegrees)
//userMarker.title = typeOfPlaces[row]
userMarker.snippet = ""
delegate?.addPinPointWillDismiss(userMarker)
dismiss(animated: true)
}
}

How can I add a button to MKPointAnnotation and open Maps?

I would have to add a button for my particular point of entry , where I click to open the Maps app already passing the coordinates of the selected point. Does anyone know how to do? my code is this. The image is what I would have.
My code:
import Foundation
import UIKit
import MapKit
import CoreLocation
class PuntiVenditaController: UIViewController, MKMapViewDelegate {
#IBOutlet weak var menuButton:UIBarButtonItem!
#IBOutlet weak var mapView: MKMapView!
let regionRadius: CLLocationDistance = 1000
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if revealViewController() != nil {
menuButton.target = revealViewController()
menuButton.action = "revealToggle:"
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
let location = CLLocationCoordinate2D(latitude: 41.225891, longitude: 16.291489)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region, animated: true)
mapView.showsPointsOfInterest = false
mapView.showsUserLocation = true
displayMarkers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(coordinateRegion, animated: true)
}
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView{
println(view.annotation.title) // annotation's title
println(view.annotation.subtitle) // annotation's subttitle
//Perform a segue here to navigate to another viewcontroller
// On tapping the disclosure button you will get here
}
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
println("viewForannotation")
if annotation is MKUserLocation {
//return nil
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
//println("Pinview was nil")
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
}
var button = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton // button with info sign in it
pinView?.rightCalloutAccessoryView = button
return pinView
}
func displayMarkers() -> Void
{
let annotationView = MKAnnotationView()
// Adding button here wont do anything so remove these two lines
let detailButton: UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
annotationView.rightCalloutAccessoryView = detailButton
// For adding button we have to use a method named as viewForAnnotation
let annotation = MKPointAnnotation()
let name = "Title"
let latitude = 41.225891
let longitude = 16.291489
annotation.title = name
var markerLatitude: Double = latitude
var markerLongitude: Double = longitude
let location = CLLocationCoordinate2D(latitude: markerLatitude, longitude: markerLongitude)
annotation.coordinate = location
annotation.subtitle = "Subtitle"
mapView.addAnnotation(annotation)
}
}
You can open an URL to open the Maps App at a specific point/address:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
But I don't think, you can design a custom marker within the Maps App

Resources