The android google map api fuselocation provides location way far from my current location for geofenced location - location

The android google map api fuse location gives location way far from my current location.
Here are the scenarios observerd:
If the location is off and make it on from the app prop screen then provides most accurate location. Means location refresh provides most accurate location.
After waiting of 5 - 10 min then current location provided.
val locationSettingResponse = LocationServices.getSettingsClient(this.context).checkLocationSettings(
mLocationSettingsRequest
)
locationSettingResponse.addOnSuccessListener { it ->
val lastLocation = mFusedLocationClient.lastLocation
lastLocation.addOnSuccessListener { location ->
if (location != null) {
onLocationFound.invoke(
LatLng(
location.latitude,
location.longitude
)
)
} else {
Toast.makeText(
context,
"Location not found",
Toast.LENGTH_SHORT
).show();
}
}
lastLocation.addOnFailureListener { exception ->
Log.e("$TAG addOnFailureListener ", "Geofence error")
Log.e("$TAG addOnFailureListener ", exception.toString())
throw LocationException(exception.message.toString())
}
}

Related

DJIGimbalAttitudeAction in Timeline mission

i am trying Timeline mission. I created timeline mission with basic flow like:-
takeoff Action
DJIGoToAction()
DJIGimbalAttitudeAction()
DJIShootPhotoAction()
DJIHotpointAction()
DJIGoHomeAction()
When i am trying with DJI Mavic Pro then mission is executed successfully but same sequence i am trying with Phantom 4 and it is not executing at all. Moreover i am not getting any error with Phantom 4 device.
Phantom 4 is standing at one place after executing GoToAction() and not able to execute DJIGimbalAttitudeAction().
Here is my sample code:-
func createTimeline() {
let goToAction = DJIGoToAction(coordinate: coordinate, altitude: kTargetAltitude)
// DJIShootPhotoAction works if there is SD card available in the drone
// The captured photo can be read from SD card
let shootPhotoAction = DJIShootPhotoAction()
let continuousShootPhotoAction = DJIShootPhotoAction(photoCount: 24, timeInterval: 3.0, waitUntilFinish: false)
let hotPointMission1 = self.defaultHotPointAction(location: coordinate, altitude: kTargetAltitude, radius: Float(20.0))!
let gimbalAction1 = DJIGimbalAttitudeAction(attitude: DJIGimbalAttitude(pitch: -90.0, roll: 0.0, yaw: 0.0))
gimbalAction1?.completionTime = 2
let returmHomeAction = DJIGoHomeAction()
timelineActions = [ goToAction, shootPhotoAction, continuousShootPhotoAction, hotPointMission1, returmHomeAction] as! [DJIMissionControlTimelineElement]
}
func startTimeline() {
self.addListenerForTimelineUpdates()
self.startTakeoff(completion: { (error) in
guard error == nil else { return }
logText += "\n start timeline"
DJISDKManager.missionControl()?.scheduleElements(timelineElements)
DJISDKManager.missionControl()?.startTimeline()
})
}
func addListenerForTimelineUpdates() {
DJISDKManager.missionControl()?.addListener(self, toTimelineProgressWith: { (event, element, error, info) in
guard error == nil else { return }
print("### \n\n Event: \(event.rawValue) \n Element:\(String(describing: element)) \n Error: \(String(describing: error)) \n Info: \(String(describing: info)) \n\n ")
//once event is finished, stop the timeline and initiate return home
if event.rawValue == DJIMissionControlTimelineEvent.finished.rawValue && element == nil {
logText += "DJIMissionControlTimelineEvent.finished, stop timeline and remove listeners"
DJISDKManager.missionControl()?.removeAllListeners()
DJISDKManager.missionControl()?.stopTimeline()
}
})
}
}
I tried my best but not able to fix this. I am working with DJI IOS SDK 4.10/4.11 & Xcode 10.2.
Any help would be much appreciated.
Thanks in advance.

Mkmapview - Putting an annotation on every grocery store within a specific region - SWIFT

I want to put an annotation on every grocery store within a specific area. I already have my mkmapview working and tracking my current location.
Thanks in advance!
Give it a try, unfortunately I'm not in situation to test it right now, but this piece of code should serve your requirement:
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "Groceries"
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start(completionHandler: {(response, error) in
if error != nil {
print("Error occured in search:
\(error!.localizedDescription)")
} else if response!.mapItems.count == 0 {
print("No matches found")
} else {
print("Matches found")
for item in response!.mapItems {
print("Name = \(item.name)")
print("Phone = \(item.phoneNumber)")
}
}
})

Swift 2 Mapkit Get City from user location

Is it possible to get the name of the city and put that one into an array of strings from the user location, using Mapkit?
I already know how to get the user location so you dont have to go into that.
Yes you can with using CLGeocoder class try to use this code
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: newCoordinates.latitude, longitude: newCoordinates.longitude),
completionHandler: {(placemarks, error) -> Void in
if error != nil {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}
if placemarks!.count > 0 {
let pm = placemarks![0]
let c = pm.locality // city of place mark
}
else {
annotation.title = "Unknown Place"
self.outletOfMapView.addAnnotation(annotation)
print("Problem with the data received from geocoder")
}
})

xcode gamcecenter no player' score displayed

the following code is used to get current player' score from GameCenter but it does not show any submitted score:
if GKLocalPlayer.localPlayer().authenticated {
let gkScore = GKScore(leaderboardIdentifier: "myID")
gkScore.value = score
GKScore.reportScores([gkScore], withCompletionHandler: ( { (error: NSError!) -> Void in
if (error != nil) {
println("Error: " + error.localizedDescription);
} else {
println("Score reported: \(gkScore.value)")
}
}
Every time app is running error with localizedDescription is displayed but not real score is displayed / reported:
Error: The requested operations could not be completed because one or more parameters are invalid.
Score reported: 0
Any idea how to fix this while testing app on device?
Thanks for any feedback.
Regards
simoasis

get user's location info using facebook ios sdk in swift

I couldn't find any info about getting user's location info in swift and xcode 6
I tried
var fbcity = user.objectForKey("location")
var fbcountry = user.objectForKey("country")
But didn't work.
Any idea how to achieve this ?
Perhaps you could supply us with a little more information, e.g. which Facebook SDK you are using and what parameters FBSDKGraphRequest has to return user. Note that there is no specific information about country, the location field in the user node when your send a graph request for the user profile. It will return the subfields: id and name, where name is
With the latest Facebook iOS SDK 4.0 you can do something like:
override func viewDidLoad() {
super.viewDidLoad()
self.loginView.delegate = self
if FBSDKAccessToken.currentAccessToken() != nil {
fetchUserData()
} else {
loginView.readPermissions = ["public_profile", "email", "user_friends"]
}
}
func fetchUserData() {
let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if error != nil {
// Process error
println("Error: \(error)")
} else {
let location: NSDictionary! = result.valueForKey("location") as NSDictionary
let city: NSString = location.valueForKey("name") as NSString
}
})
}
More detailed info can be found on Facebook Graph API User page.

Resources