Google Maps does not load the map on iPhone. However when I connect the iPhone to Xcode and execute the project, it loads the map correctly.
This is my code:
let camera = GMSCameraPosition.camera(withLatitude: -33.868, longitude: 151.2086, zoom: 14)
let mapViewtest = GMSMapView.map(withFrame: .zero, camera: camera)
let marker = GMSMarker()
marker.position = camera.target
marker.snippet = "Hello World"
//marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = mapViewtest
view = mapViewtest
The console shows me this but I do not know if it has something to do with the issue:
CoreData: annotation: Failed to load optimized model at path
'/var/containers/Bundle/Application/33FC89CC-DC52-4212-A361-F54DD2AC3CD9/App_name.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
EDIT
The problem is that the map doesn't appear, but markers appear correctly
Run app on Iphone connected to xcode
Run app whitout xcode
check your apikey again.
even if you use a wrong apikey, map will be show on a simulator, but doesn't work on device.
Related
This is my custom location set inside the iOS 10.0 iPhone 6 and iOS 11.2 iPhone 6 simulators.
And this is the code by which I am trying to open the iPhone's inbuilt Apple Map and show the directions from user's (above set) current location to the provided destination locations.
let regionDistance: CLLocationDistance = 1000
let coordinates = CLLocationCoordinate2D(latitude: 26.025860999999999, longitude: 56.089238999999999)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span),
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] as [String : Any]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "Federal Electricity & Water Authority"
mapItem.openInMaps(launchOptions: options)
but this is not working for at all. It's showing me the error like below,
Note:
I have given the location access permission to the default Map
application.
All 4 MKLaunchOptionsDirectionsModeKey is not showing
the direction.
Tested it on the Simulator and a real device and it is not working in either place.
Setting destination coordinates like this doesn't help. let coordinates = CLLocationCoordinate2D(latitude: 26.025861, longitude: 56.089239)
Please help!
As Indrajeet commented, the directions in iPhone's Apple Map is limited to the countries which are listed in this URL.
So in my case, UAE is not listed currently.
Will update this answer in future once UAE will be listed.
I am trying to integrate Uber SDK with my current iOS app.
I have Xcode :- 8.1 iOS :-10.1 and swift version :- 3.0
I have done setup for "Carthage" for Uber integration.
i am calling requestRide method and its always giving ride=nil
let parameterBuilder = RideParametersBuilder()
parameterBuilder.setProductID("a1111c8c-c720-46c3-8534-2fcdd730040d")
let pickupLocation = CLLocation(latitude: 37.770, longitude: -122.466)
parameterBuilder.setPickupLocation(pickupLocation, nickname: "California Academy of Sciences")
let dropoffLocation = CLLocation(latitude: 37.791, longitude: -122.405)
parameterBuilder.setDropoffLocation(dropoffLocation, nickname: "Pier 39")
let ridesClient = RidesClient()
ridesClient.requestRide(parameterBuilder.build(), completion: { ride, response in
}
Please help me.
i stuck here not able to execute my project. any suggestion will be useful for me.
Thanks in advance.
I am making a single view application in Xcode, with Google Map SDK. I have followed instructions online and my application can successfully load the google map view. I have also enabled myLocation, so that myLocation button shows on the map view.
I understand that clicking the myLocation button will change the camera location automatically, but I'm wondering what I should do to use the data of myLocation (say to add a marker or add a path node)?
I've tried directly accessing mapView.myLocation, for example
let lat = mapView.myLocation?.coordinate.latitude
let long = mapView.myLocation?.coordinate.longitude
path.addCoordinate(CLLocationCoordinate2D(latitude: lat!, longitude: long!))
However, this will crash the applicaton and throw:
fatal error: unexpectedly found nil while unwrapping an Optional value
What does this error message mean and how should I resolve this?
The error says that myLocation property of mapView is nil. You should check if there is a value before accessing it.
if let myLocation = mapView.myLocation {
let lat = myLocation.coordinate.latitude
let long = myLocation.coordinate.longitude
path.addCoordinate(CLLocationCoordinate2D(latitude: lat, longitude: long))
}
Also verify why myLocation is nil. It might be that the user didn't allow location services.
This will not give any errors:
let lat = mapView.myLocation?.coordinate.latitude ?? give any value of latitude
let long = mapView.myLocation?.coordinate.longitude ?? give any value of longitude
I would like to provide multiple MapKit annotations (pins) in Xcode 7.0.1 but have no idea how to, I've created one annotation:
let location = CLLocationCoordinate2DMake(50.714141, -1.874704)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Bournemouth Pier"
mapView.addAnnotation(annotation)
It seems I can't just copy and paste this code with different titles and coordinates which is really annoying and quite frankly stupid. (you can tell how annoyed I am) any help would be appreciated cheers.
You definitely can add multiple annotations this way. Make sure you instantiate a new MKPointAnnotation for each one, though.
For example:
var location = CLLocationCoordinate2DMake(50.714141, -1.874704)
var annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Bournemouth Pier"
mapView.addAnnotation(annotation)
location = CLLocationCoordinate2DMake(51.714141, -2.874704)
annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Gwernesney"
mapView.addAnnotation(annotation)
If you're still having trouble adding multiple annotations, please edit your question, showing us how you are trying to do that. You've shown an attempt at adding a single annotation, but not how you've attempted to add multiple ones.
I don't know about anyone else, but EventKit seems to have very little in terms resources and tutorials online for you to refer to for help.
I need to trigger an alarm when a user hits a radius of a set of coordinates, I wasn't sure of the best ay to do this, I was torn between local notifications, and EventKit reminders.
I decided to go for eventKit as I felt that I could do more with more the alarms and it was the most practical way to do it however, having not known much about EventKit i had some issues.
Anyway I've managed to get together and build a sample project which works and triggers an alert when the user leaves their current location, the only problem is, is that I almost want to do the complete opposite of that, I want to trigger an alert when the user enters a set of coordinates, I assume that most of the code is transferrable, however I seem to be stuck on one bit mainly.
// Creates an EKStructuredLocation Instance with a title of "Current Location"
let location = EKStructuredLocation(title: "Current Location")
// Uses the last location update extracted from the locations array to supply you're current location
location.geoLocation = locations.last as! CLLocation
// Location is added to a newly created alarm instance
let alarm = EKAlarm()
alarm.structuredLocation = location
// This alarm is triggered when the user moves away from the location proximity
alarm.proximity = EKAlarmProximityLeave
stationReminder.addAlarm(alarm)
I'm struggling to find how to set the location of the alarm to coordinates rather than users location.
I tried changing this
location.geoLocation = locations.last as! CLLocation
to
location.geoLocation = CLCircularRegion(circularRegionWithCenter: CLLocationCoordinate2D(latitude: 37.33233141, longitude: -122.03121860), radius: 50.0, identifier: "Location1")
but this doesn't work, i believe i am on the right track but i am throwing up this error: Cannot assign a value of type 'CLCircularRegion!' to a value of type 'CLLocation!'
I've tried loads of things with no resolve, does anybody have any experience with this and know how to help?
I also assume i'll have to change the following from this
alarm.proximity = EKAlarmProximityLeave
to this
alarm.proximity = EKAlarmProximityEnter
UPDATE
I've taken on board some comments below and tried a bunch of other things to get this to work, I feel like I am so close but somethings just missing. I cannot get this alarm to trigger. Excuse all the code comments, it's just so you can see some of the attempts i have made at fixing this.
can anyone see anything wrong with this code for the alarm?
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
// Stops location manager from sending further updates
locationManager.stopUpdatingLocation()
// Creates a new EKReminder which is named and initialised with text from the UITextField
let stationReminder = EKReminder(eventStore: appDelegate!.eventStore)
stationReminder.title = locationText.text
// Stores the previously created EKReminder in the default calendar
stationReminder.calendar = appDelegate!.eventStore!.defaultCalendarForNewReminders()
// Creates an EKStructuredLocation Instance with a title of "Current Location"
let location = EKStructuredLocation(title: "Destination: Bournemouth Station")
// Uses the last location update extracted from the locations array to supply you're current location
// location.geoLocation = locations.last as! CLLocation
// location.geoLocation = CLCircularRegion(circularRegionWithCenter: CLLocationCoordinate2D(latitude: 37.33233141, longitude: -122.03121860), radius: 50.0, identifier: "Location1")
// location.geoLocation = CLLocation(latitude: 50.742771, longitude: -1.895072)
location.radius = 50.0
location.geoLocation = CLLocation(latitude:50.742771, longitude:-1.895072)
// location.radius = 10.0 // metres
// Location is added to a newly created alarm instance
let alarm = EKAlarm()
alarm.structuredLocation = location
// This alarm is triggered when the user moves away from the location proximity
// alarm.proximity = EKAlarmProximityEnter
alarm.proximity = EKAlarmProximityEnter // "geofence": we alarm when *arriving*
// but this will have no effect until Reminders is granted Location access...
// and in iOS 8 it won't even ask for it until it is launched
// also, in iOS 8 the separate background usage pref is withdrawn;
// instead, auth of Reminders for "when in use" covers this...
// ...because it means "this app *or one of its features* is visible on screen"
stationReminder.addAlarm(alarm)
// Now we have a fully configured reminder which we save in the Event Store
var error: NSError?
appDelegate!.eventStore?.saveReminder(stationReminder,
commit: true, error: &error)
if error != nil {
println("Reminder failed with error \(error?.localizedDescription)")
}
}
Looks like EKEvent has an EKStructuredLocation, which you are using correctly. However, you need to be careful of the type of the geoLocation property. It should be a CLLocation, which is not the same as a CLCircularRegion.
Steps to fix:
check the docs for EKStructuredLocation https://developer.apple.com/library/mac/documentation/EventKit/Reference/EKStructuredLocationClassRef/index.html
set the location.geoLocation to a CLLocation that you create from latitude, longitude coordinates. (check the docs for CLLocation: https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/swift/cl/CLLocation)
geoLocation = CLLocation(latitude: 37.33233141, longitude: -122.03121860)
set the geoLocation.radius separately location.radius = 50.0
at that point setting proximityEnter should work as you expected