airsoftFreak
airsoftFreak

Reputation: 1608

How do i parse latitude and longitude to google maps?

My goal is to parse lat and long to the google maps, assume that mapView is the view object of GMSMapView class and I have initialized it.

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.delegate = self
       // Ask for Authorisation from the User.
    self.locationManager.requestAlwaysAuthorization()
    // For use in foreground
    self.locationManager.requestWhenInUseAuthorization()

    // This is where I will parse the lat and long
    var coordinate: CLLocationCoordinate2D
    coordinate = CLLocationCoordinate2D(latitude: 3.203119, longitude: 101.7276145)
    mapView.projection.containsCoordinate(coordinate)
}

Whenever I run it, it doesn't show the marker of the custom coordinates

Upvotes: 0

Views: 218

Answers (1)

Ronak Kalavadia
Ronak Kalavadia

Reputation: 397

let camera = GMSCameraPosition.cameraWithLatitude(yourLatitude,
                                                      longitude: yourLongitude, zoom: 15)
    mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    mapView.delegate = self
    mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
    self.view.addSubview(mapView)



    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(yourLatitude, yourLongitude)
    marker.title = strTitleOfMarker
    marker.snippet = strSubTitleOfMarker
    marker.map = mapView



// Add this to .plist file
<key>NSLocationAlwaysUsageDescription</key>
<string>Access your location</string>

Upvotes: 1

Related Questions