Cannot Get My Location to Show Up in Google Maps in iOS 8

Cannot get my location to show up in Google Maps in iOS 8

You need your CLLocationManager to be retained, otherwise it is released before it gets a chance to present the authorisation dialog.

class MapViewController: UIViewController {

@IBOutlet var mapView: GMSMapView!

var firstLocationUpdate: Bool?
let locationManager=CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()

self.locationManager.requestWhenInUseAuthorization()

let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 12)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.settings.compassButton = true
mapView.settings.myLocationButton = true

mapView.addObserver(self, forKeyPath: "myLocation", options: .New, context: nil)

dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.mapView.myLocationEnabled = true
})
println(mapView.myLocation)
view = mapView

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}

Google Map SDK, iOS , cannot get myLocation

Heres some code to parse your location... I think your just having an issue extracting the location info for the map view to load

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -> Void in
if (error != nil) {
println("Error:" + error.localizedDescription)
return
}

if placemarks.count > 0 {
let pm = placemarks[0] as CLPlacemark
pm.location.coordinate;
mapView.camera = GMSCameraPosition(target:pm.location.coordinate, zoom:15,bearing:0, viewingAngle:0)
locationManager.stopUpdatingLocation()

}else {
println("Error with data")
}
}

I haven't compiled this code and I'm not swift savvy but hopefully this helps

To change your location go to Edit Scheme...
Sample Image

Then select whatever location you want to simulate
Sample Image

Google map sdk for IOS 8 does not update location

Google Maps SDK v1.8.1 doesn't request the location authorization that is needed in iOS8, so you need to do this in your application.

Use the CLLocationManager's requestWhenInUseAuthorization method, and in the authorization changed delegate, enable location updates in the map view when authorization can be given.

Also, don't forget to add the correct keys in the info.plist to explain to your users why you need their location, as without this the call to requestWhenInUseAuthorization don't do anything.

Google Maps API not showing my location

I followed the tutorial here, specifically the part titled My Location. I ignored the part about func locationManager and instead put the call for viewMap.myLocationEnabled = true in viewDidLoad. The tutorial's overriding of observeValueForKeyPath seems to be outdated, which required some tweaking but here is my full code:

class ViewController: UIViewController, CLLocationManagerDelegate {

// MARK: Properties
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
let stdZoom: Float = 12
var didFindMyLocation = false

override func viewDidLoad() {
super.viewDidLoad()

self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.mapView.myLocationEnabled = true
self.mapView.settings.myLocationButton = true

self.mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if !didFindMyLocation {
let myLocation: CLLocation = change![NSKeyValueChangeNewKey] as! CLLocation
self.mapView.camera = GMSCameraPosition.cameraWithTarget(myLocation.coordinate, zoom: 10.0)
self.mapView.settings.myLocationButton = true

didFindMyLocation = true
}
}

}

Cant get current location (GPS) on google maps ios sdk

Did you add NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription (in your case it's this one) keys in your .plist file. Because if the alert view asking for authorization is not showing this might be the issue.

Google Maps iOS SDK mylocation button not showing

i find to show button and get userlocation

// Rather than setting -myLocationEnabled to YES directly,
// call this method:

- (void)enableMyLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

if (status == kCLAuthorizationStatusNotDetermined)
[self requestLocationAuthorization];
else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted)
return; // we weren't allowed to show the user's location so don't enable
else
[self.view setMyLocationEnabled:YES];
}

// Ask the CLLocationManager for location authorization,
// and be sure to retain the manager somewhere on the class

- (void)requestLocationAuthorization
{
_locationAuthorizationManager = [[CLLocationManager alloc] init];
_locationAuthorizationManager.delegate = self;

[_locationAuthorizationManager requestAlwaysAuthorization];
}

// Handle the authorization callback. This is usually
// called on a background thread so go back to main.

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status != kCLAuthorizationStatusNotDetermined) {
[self performSelectorOnMainThread:@selector(enableMyLocation) withObject:nil waitUntilDone:[NSThread isMainThread]];

_locationAuthorizationManager.delegate = nil;
_locationAuthorizationManager = nil;
}
}

Google Maps API (GMS) map doesn't show up

I believe the best way to do it is to use key-value observing (KVO):

override func viewWillAppear(animated: Bool) {
mapView.addObserver(self, forKeyPath: "myLocation", options:0, context:nil)
}

deinit {
mapView.removeObserver(self, forKeyPath:"myLocation", context:0)
}

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if(keyPath! == "myLocation"]) {
let location = [object myLocation]

let target =
CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);

mapView.animateToLocation(target)
mapView.animateToZoom(17)
}
}


Related Topics



Leave a reply



Submit