I have a marker on map. When scroll map, then the marker also moves. I can find the marker coordinates, but how to find place information using that coordinate?
Place information of current location
func locate() {
placesClient.currentPlace(callback: { (placeLikelihoodList, error) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
let placeInfo = getCurrentPlaceInformation()
self.placeNameLbl.text = placeInfo.name
self.placeAddressLbl.text = placeInfo.address
if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
print("LOG: place name : \(place.name), place Address : \(place.formattedAddress)")
PLACE_NAME = place.name
PLACE_ADDRESS = place.formattedAddress ?? ""
let placeInfo = getCurrentPlaceInformation()
self.placeNameLbl.text = placeInfo.name
self.placeAddressLbl.text = placeInfo.address
}
}
})
}
How to find custom coordinates to find place information?
Apple reverse Geocode API
import CoreLocation
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(<#T##location: CLLocation##CLLocation#>, completionHandler: <#T##CLGeocodeCompletionHandler##CLGeocodeCompletionHandler##([CLPlacemark]?, Error?) -> Void#>)
Google reverse Geocode API
Add GoogleMaps to project (can use pods)
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(position) { response, error in
//
if error != nil {
print("reverse geodcode fail: \(error!.localizedDescription)")
} else {
if let places = response?.results() {
if let place = places.first {
if let lines = place.lines {
print("GEOCODE: Formatted Address: \(lines)")
}
} else {
print("GEOCODE: nil first in places")
}
} else {
print("GEOCODE: nil in places")
}
}
}
func getAddrFrmLtLng(latitude:Any, longitude:Any){
let geoCoder = CLGeocoder()
let location = CLLocation(latitude: latitude as! CLLocationDegrees, longitude: longitude as! CLLocationDegrees)
geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
var placeMark: CLPlacemark!
placeMark = placemarks?[0]
self.displayLocationInfo(placemark: placeMark)
})
}
func displayLocationInfo(placemark: CLPlacemark?) -> String {
var locality = ""
var postalCode = ""
var administrativeArea = ""
var country = ""
var sublocality = ""
var throughfare = ""
var name = ""
if let containsPlacemark = placemark {
//stop updating location to save battery life
// locationManager.stopUpdatingLocation()
locality = (containsPlacemark.locality != nil) ? containsPlacemark.locality! : ""
postalCode = (containsPlacemark.postalCode != nil) ? containsPlacemark.postalCode! : ""
administrativeArea = (containsPlacemark.administrativeArea != nil) ? containsPlacemark.administrativeArea! : ""
country = (containsPlacemark.country != nil) ? containsPlacemark.country! : ""
sublocality = (containsPlacemark.subLocality != nil) ? containsPlacemark.subLocality! : ""
throughfare = (containsPlacemark.thoroughfare != nil) ? containsPlacemark.thoroughfare! : ""
}
var adr: String = ""
if throughfare != "" {
adr = throughfare + ", "
}
if sublocality != "" {
adr = adr + sublocality + ", "
}
if locality != "" {
adr = adr + locality + ", "
}
if administrativeArea != "" {
adr = adr + administrativeArea + ", "
}
if postalCode != "" {
adr = adr + postalCode + ", "
}
if country != "" {
adr = adr + country
}
print(adr)
return adr
}
Related
I want to get the address from the coordinate. I have attached my code below..
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last!
let latvalue = lastLocation.coordinate.latitude
let lngvalue = lastLocation.coordinate.longitude
self.db_latvalue = latvalue
self.db_lngvalue = lngvalue
let location = CLLocation(latitude: latvalue, longitude:lngvalue)
let address = CLGeocoder.init()
address.reverseGeocodeLocation(CLLocation.init(latitude: latvalue, longitude:lngvalue)) { (places, error) in
if error == nil{
if let place = places{
print("addressshowingssq \(place)")
self.db_address = "\(place)"
}
}
}
Output:
[L-30 2nd A Main Road, L-30 2nd A Main Road, HSR Layout, Bengaluru,
Karnataka 560102, India # <+12.91597974,+77.62879254> +/- 100.00m,
region CLCircularRegion (identifier:'<+12.91597974,+77.62879254>
radius 70.94', center:<+12.91597974,+77.62879254>, radius:70.94m)]
I want only the address as i mention below
L-30 2nd A Main Road, L-30 2nd A Main Road, HSR Layout, Bengaluru,
Karnataka 560102
I researched google i got different solution so i got confused.
Update
I have done a few modification to iVarun's solution. This is simpler. and working.
First, add this function:
func geocode(latitude: Double, longitude: Double, completion: #escaping (CLPlacemark?, Error?) -> ()) {
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: latitude, longitude: longitude)) { completion($0?.first, $1) }
}
After that,
get the address:
geocode(latitude: latvalue, longitude: lngvalue) { placemark, error in
guard let placemark = placemark, error == nil else { return }
// you should always update your UI in the main thread
DispatchQueue.main.async {
// update UI here
print("address1:", placemark.thoroughfare ?? "")
print("address2:", placemark.subThoroughfare ?? "")
print("city:", placemark.locality ?? "")
print("state:", placemark.administrativeArea ?? "")
print("zip code:", placemark.postalCode ?? "")
print("country:", placemark.country ?? "")
}
}
Result:
address1: Rua Casuarina
address2: 443
city: Rio de Janeiro
state: RJ
zip code: 20975
country: Brazil
As #iOSer indicated, CLPlacemark is capable of giving you this part of the string, However.
You could split the string:
let output:String = "[L-30 2nd A Main Road, L-30 2nd A Main Road, HSR Layout, Bengaluru, Karnataka 560102, India # <+12.91597974,+77.62879254> +/- 100.00m, region CLCircularRegion (identifier:'<+12.91597974,+77.62879254> radius 70.94', center:<+12.91597974,+77.62879254>, radius:70.94m)]"
let items = output.components(separatedBy: "#")
print(items[0])
Becuse the # will be always included, you could skip the rest.
Result:
Hope this will help you:
address.reverseGeocodeLocation(CLLocation.init(latitude: latvalue, longitude:lngvalue)) { (places, error) in
if error == nil{
let placeMark = places! as [CLPlacemark]
if placeMark.count > 0 {
let placeMark = places![0]
var addressString : String = ""
if placeMark.subThoroughfare != nil {
addressString = addressString + placeMark.subThoroughfare! + ", "
}
if placeMark.thoroughfare != nil {
addressString = addressString + placeMark.thoroughfare! + ", "
}
if placeMark.subLocality != nil {
addressString = addressString + placeMark.subLocality! + ", "
}
if placeMark.locality != nil {
addressString = addressString + placeMark.locality! + ", "
}
if placeMark.administrativeArea != nil {
addressString = addressString + placeMark.administrativeArea! + ", "
}
if placeMark.country != nil {
addressString = addressString + placeMark.country! + ", "
}
if placeMark.postalCode != nil {
addressString = addressString + placeMark.postalCode! + " "
}
print(addressString)
}
}
}
Output:
L-30, 2nd A Main Road, HSR Layout, Bengaluru, Karnataka, India, 560102
Swift 3
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
let objLocation = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude)
CLGeocoder().reverseGeocodeLocation(objLocation) { (placemarksArray, error) in
if error != nil {
print("Reverse geocoder failed with error" + (error?.localizedDescription)!)
return
}
if (placemarksArray?.count)! > 0 {
let objPlacemark = placemarksArray?[0]
self.generateAddress(objPlacemark: objPlacemark!)
self.locationManager?.stopUpdatingLocation()
self.locationManager = nil
}
else {
print("Problem with the data received from geocoder")
}
}
}
Function Parsing placemark to string...
func generateAddress(objPlacemark : CLPlacemark) -> String {
print("objPlacemark : \(objPlacemark.description)")
var completeAddress = ""
if objPlacemark.name != nil {
completeAddress = String(describing: objPlacemark.name!)
}
if objPlacemark.thoroughfare != nil && (objPlacemark.name != objPlacemark.thoroughfare) {
completeAddress = completeAddress + ", " + String(describing: objPlacemark.thoroughfare!)
}
if objPlacemark.subThoroughfare != nil {
completeAddress = completeAddress + ", " + String(describing: objPlacemark.subThoroughfare!)
}
if objPlacemark.subLocality != nil {
completeAddress = completeAddress + "," + String(describing: objPlacemark.subLocality!)
}
if objPlacemark.locality != nil {
completeAddress = String(describing: objPlacemark.locality!)
}
if objPlacemark.postalCode != nil {
completeAddress = completeAddress + "," + String(describing: objPlacemark.postalCode!)
}
if objPlacemark.administrativeArea != nil {
completeAddress = completeAddress + "," + String(describing: objPlacemark.administrativeArea!)
}
if objPlacemark.isoCountryCode != nil {
completeAddress = completeAddress + "," + String(describing: objPlacemark.isoCountryCode!)
}
print("completeAddress : \(completeAddress)")
return completeAddress
}
CLGeocodeCompletionHandler contains an array of CLPlacemark. You can access its properties such as name, locality, isoCountryCode etc to form a complete address!!
This is the number 1 crash of my application in the AppStore. Problem is I can't find a solution to this thing, because I can't reproduce it and don't know what is causing it. The crashlog says the following:
Thread 0.8 is didUpdateLocations.
I thought it might be in checkStealRange(), but I don't see something wrong with that.
func checkStealRange() {
var objectsWithdistance = [PFObject]()
stealobject = nil
print("checkin steal and setting stealobject to nil")
if nearbystreets.count != 0 {
for object in self.nearbystreets {
if let lon = object["lon"] as? Double, let lat = object["lat"] as? Double{
let locationStreet = CLLocation(latitude: lat, longitude: lon)
if let currentLocation = self.locationManager.location {
let distance = currentLocation.distance(from: locationStreet)
object["distance"] = distance
objectsWithdistance.append(object)
} else {
if self.lastlocationregionset != nil {
let distance = self.lastlocationregionset!.distance(from: locationStreet)
object["distance"] = distance
objectsWithdistance.append(object)
}
}
}
}
} else {
print("no nearby streets loaded to check for steal")
stealButton.isEnabled = false
return
}
if objectsWithdistance.count > 0 {
print("objectsWithdistance count:", objectsWithdistance.count)
let sortedArray = (objectsWithdistance as NSArray).sortedArray(using: [
NSSortDescriptor(key: "distance", ascending: true)
])
for object in sortedArray {
guard let street = object as? PFObject else { continue }
if let streetDistance = street["distance"] as? Double {
var allowedDistance = Game.steal.stealMinDistance +
Game.steal.stealDistancePerLevel * Double(Main().level())
if Main().getStealBoost() {
allowedDistance += 250
}
//print("distance:", streetDistance, "allowed:", allowedDistance)
guard let user = street["current_owner"] as? PFUser else { continue }
if user != PFUser.current() && streetDistance <= allowedDistance {
print("found steal")
self.stealobject = street
break
}
}
}
} else {
print("checkin steal failed")
stealButton.isEnabled = false
return
}
print("nearbystreet count:", nearbystreets.count)
if !self.timecheat && stealobject != nil {
stealButton.isEnabled = true
} else {
stealButton.isEnabled = false
}
}
Re-wrote the function using Parse localdata storage, and that fixed the trick.
func checkStealRange() {
stealobject = nil
let query = PFQuery(className: "SHStreets")
if let currentLocation = self.locationManager.location {
let userGeoPoint = PFGeoPoint(latitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
query.whereKey("geo", nearGeoPoint: userGeoPoint, withinKilometers: 5)
} else {
print("no location, returning from check steal range")
self.stealButton.isEnabled = false
return
}
query.fromLocalDatastore()
query.findObjectsInBackground { (objects : [PFObject]?, error: Error?) in
if error != nil {
print(error as Any)
self.stealButton.isEnabled = false
return
}
if objects == nil || objects!.count == 0 {
print("no nearby streets loaded to check for steal")
self.stealButton.isEnabled = false
return
}
if objects != nil {
for (index, object) in objects!.enumerated() {
guard let lon = object["lon"] as? Double else { continue }
guard let lat = object["lat"] as? Double else { continue }
let locationStreet = CLLocation(latitude: lat, longitude: lon)
if let currentLocation = self.locationManager.location {
let distance = currentLocation.distance(from: locationStreet)
//steal distance
var allowedDistance = Game.steal.stealMinDistance + Game.steal.stealDistancePerLevel * Double(Main().level())
if Main().getStealBoost() {
allowedDistance += 250
}
print("distance for street:" , index + 1, "is", distance, "allowed:", allowedDistance)
guard let user = object["current_owner"] as? PFUser else { continue }
if user != PFUser.current() && distance <= allowedDistance {
print("found steal")
self.stealobject = object
if !self.timecheat && self.stealobject != nil && !self.stealinprogress {
self.stealButton.isEnabled = true
} else {
self.stealButton.isEnabled = false
}
return
}
}
}
}
}
}
My app has two tabs. On the first tab a bunch of tab annotations are created based on an attraction. When you click on the annotation view, it goes to the 2nd tab which is a detail view controller of the attraction. I am wondering how I can pass the location of the attraction to the detailVC that way I can have the pin at the same address. Here is what I have so far, and there are some inconsistencies, as the address displayed on the detail vc is not equal to the address of the attraction.
func performSearch(input:String) {
attractionsMap.removeAnnotations(attractionsMap.annotations);
matchingItems.removeAll()
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = input
println(input);
request.region = attractionsMap.region;
let search = MKLocalSearch(request: request)
search.startWithCompletionHandler({(response:
MKLocalSearchResponse!,
error: NSError!) in
if error != nil {
println("Error occured in search: \(error.localizedDescription)")
} else if response.mapItems.count == 0 {
println("No matches found")
} else {
println("Matches found")
for item in response.mapItems as! [MKMapItem] {
println("Name = \(item.name)")
println("Phone = \(item.phoneNumber)")
matchingItems.append(item as MKMapItem)
println("Matching items = \(matchingItems.count)")
var placemark = item.placemark;
var subThoroughfare:String = "";
var thoroughfare:String = "";
var locality:String = "";
var postalCode:String = "";
var administrativeArea:String = "";
var country:String = "";
var title = "";
var subtitle = "";
if (placemark.subThoroughfare != nil) {
subThoroughfare = placemark.subThoroughfare;
}
if(placemark.thoroughfare != nil) {
thoroughfare = placemark.thoroughfare;
}
if(placemark.locality != nil) {
locality = placemark.locality;
}
if(placemark.postalCode != nil) {
postalCode = placemark.postalCode;
}
if(placemark.administrativeArea != nil) {
administrativeArea = placemark.administrativeArea;
}
if(placemark.country != nil) {
country = placemark.country;
}
println("viewcontroller placmark data:");
println(locality);
println(postalCode);
println(administrativeArea);
println(country);
title = " \(subThoroughfare) \(thoroughfare) \n \(locality), \(administrativeArea) \n \(postalCode) \(country)";
subtitle = " \(subThoroughfare) \(thoroughfare)";
println(title);
var annotation = MKPointAnnotation()
annotation.coordinate = item.placemark.coordinate
annotation.title = item.name + " " + subtitle;
self.attractionsMap.addAnnotation(annotation)
}
}
})
}
This is the search and adding the pin annotations.
I then attempt to send the attractionLocation below
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var attractionsDetailViewController:AttractionsDetailViewController = segue.destinationViewController as! AttractionsDetailViewController
attractionsDetailViewController.attractionLocation = indicatedMapItem;
}
And then my Detail ViewController to implement the given address:
func getInfo() {
var latitude = attractionLocation.latitude;
var longitude = attractionLocation.longitude;
var latDelta:CLLocationDegrees = 0.000001
var longDelta: CLLocationDegrees = 0.000001
var span: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta);
var location = CLLocationCoordinate2DMake(latitude, longitude);
var realLocation = CLLocation(latitude: latitude, longitude: longitude);
CLGeocoder().reverseGeocodeLocation(realLocation, completionHandler: { (placemarks, error) -> Void in
var title = ""
var subtitle = ""
var locality = ""
if(error == nil) {
if let placemark = CLPlacemark(placemark: placemarks?[0] as! CLPlacemark) {
var subThoroughfare:String = "";
var thoroughfare:String = "";
var locality:String = "";
var postalCode:String = "";
var administrativeArea:String = "";
var country:String = "";
if (placemark.subThoroughfare != nil) {
subThoroughfare = placemark.subThoroughfare;
}
if(placemark.thoroughfare != nil) {
thoroughfare = placemark.thoroughfare;
}
if(placemark.locality != nil) {
locality = placemark.locality;
}
if(placemark.postalCode != nil) {
postalCode = placemark.postalCode;
}
if(placemark.administrativeArea != nil) {
administrativeArea = placemark.administrativeArea;
}
if(placemark.country != nil) {
country = placemark.country;
}
println("viewcontroller placmark data:");
println(locality);
println(postalCode);
println(administrativeArea);
println(country);
title = " \(subThoroughfare) \(thoroughfare) \n \(locality), \(administrativeArea) \n \(postalCode)\(country)";
subtitle = " \(subThoroughfare) \(thoroughfare)";
println(title);
self.addressLabel.text = title;
}
}
var overallLoc = CLLocationCoordinate2DMake(latitude, longitude);
var region:MKCoordinateRegion = MKCoordinateRegionMake(overallLoc, span);
var annotation = MKPointAnnotation();
annotation.coordinate = location;
annotation.title = subtitle;
self.detailMap.addAnnotation(annotation);
self.detailMap.setRegion(region, animated: true)
})
}
You can store a global variable, which is usually not recommended, or you can pass via segue, which is recommended. It's probably better to not reverse geocode again because reverse geocoding is not always the most accurate method of finding locations...
If you make your attractionLocation property in the detailsVC like this...
var attractionLocation: CLLocation?
var attractionAddress: String?
As far as I can tell, the getInfo function just needs to set the map's region and add the appropriate annotation.
Seeing as the attractionLocation property will be a CLLocation we can access it's coordinate property. And if you pass through the attractionAddress from the first screen then CLGeocoder doesn't need to be used.
func getInfo() {
// Create span for the map region
var latDelta:CLLocationDegrees = 0.000001
var longDelta: CLLocationDegrees = 0.000001
var span: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta);
// Create region for map
var region:MKCoordinateRegion = MKCoordinateRegionMake(attractionLocation!.coordinate, span);
var annotation = MKPointAnnotation();
annotation.coordinate = attractionLocation!.coordinate;
annotation.title = attractionAddress!;
self.detailMap.addAnnotation(annotation);
self.detailMap.setRegion(region, animated: true)
}
In the past I've not found CLGeocoder to be that consistent when it comes to reverse geocoding. So at least this way you can be sure the address between the two screens will be consistent.
I'm testing out reverseGeocodeLocation with this app that shows your closest address. I've gotten everything to work except for the showing of the current state that you are in (IL, NY, ext.). How do I do that? This is my current code:
CLGeocoder().reverseGeocodeLocation(userLocation)
{ (placemarks, error) -> Void in
if error != nil
{
println(error)
}
else
{
let pm = CLPlacemark(placemark: placemarks![0] as CLPlacemark)
var subThoroughtare:String = ""
var thoroughfare:String = ""
var subLocality:String = ""
var subAdministrativeArea:String = ""
var postalCode:String = ""
var country:String = ""
if pm.subThoroughfare != nil {subThoroughtare = pm.subThoroughfare!}
if pm.thoroughfare != nil {thoroughfare = pm.thoroughfare!}
if pm.subLocality != nil {subLocality = pm.subLocality!}
if pm.subAdministrativeArea != nil {subAdministrativeArea = pm.subAdministrativeArea!}
if pm.postalCode != nil {postalCode = pm.postalCode!}
if pm.country != nil {country = pm.country!}
self.addressLabel.text = "\(subThoroughtare) \(thoroughfare) \n \(subLocality) \n \(postalCode) \n \(country)"
}
}
and the output is this (example location):
County Road 1760
79529
United States
for the state you want to look at the administrativeArea
let state = pm.administrativeArea;
If you look at the definition for the CLPlacemark class it shows..
var administrativeArea: String! { get } // state, eg. CA
I have application with map where you can make an annotation by dropping a pin. How can I save the annotation, so you can see it when the application is closed and re-opened?
My code's for annotation
func addAnnotation(gesture: UIGestureRecognizer) {
if gesture.state == UIGestureRecognizerState.Began {
var touch = gesture.locationInView(self.Mapa)
var coordinate = Mapa.convertPoint(touch, toCoordinateFromView: self.Mapa)
var location = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
var loc = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
CLGeocoder().reverseGeocodeLocation(loc, completionHandler: { (placemarks, error) -> Void in
if error == nil {
let placemark = CLPlacemark(placemark: placemarks[0] as! CLPlacemark)
self.cislo = placemark.subThoroughfare != nil ? placemark.subThoroughfare : ""
self.adresa = placemark.thoroughfare != nil ? placemark.thoroughfare : ""
self.mesto = placemark.subAdministrativeArea != nil ? placemark.subAdministrativeArea : ""
self.krajina = placemark.administrativeArea != nil ? placemark.administrativeArea : ""
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.location.coordinate
annotation.title = self.adresa! + " " + self.cislo!
self.Mapa.addAnnotation(annotation)
println("Špendlík pridaný!")
}
})
}
}
In case you want to see whole code
http://pastebin.com/d89kTrL7
i would save the data into userdefaults as
func addAnnotation(gesture: UIGestureRecognizer) {
if gesture.state == UIGestureRecognizerState.Began {
var touch = gesture.locationInView(self.Mapa)
var coordinate = Mapa.convertPoint(touch, toCoordinateFromView: self.Mapa)
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setDouble(coordinate.longitude, forKey: "longitudeNameKey")
defaults.setDouble(coordinate.latitude, forKey: "latitudeNameKey")
defaults.synchronize()
var location = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
var loc = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
CLGeocoder().reverseGeocodeLocation(loc, completionHandler: { (placemarks, error) -> Void in
if error == nil {
let placemark = CLPlacemark(placemark: placemarks[0] as! CLPlacemark)
self.cislo = placemark.subThoroughfare != nil ? placemark.subThoroughfare : ""
self.adresa = placemark.thoroughfare != nil ? placemark.thoroughfare : ""
self.mesto = placemark.subAdministrativeArea != nil ? placemark.subAdministrativeArea : ""
self.krajina = placemark.administrativeArea != nil ? placemark.administrativeArea : ""
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.location.coordinate
annotation.title = self.adresa! + " " + self.cislo!
self.Mapa.addAnnotation(annotation)
println("Špendlík pridaný!")
}
})
}
}
You can save info to NSUserDefaults when the annotations are created.And somewhere in viewDidLoad method you just get all the info from user defaults and then display the annotations.
override func viewDidLoad() {
super.viewDidLoad()
loadAnnotationFromUserDefaults()
}
use loadAnnotationFromUserDefaults method to deserializes the list of coordinates previously saved to NSUserDefaults. Through this method you also load the coordinates as annotations on the map view.
func loadAnnotationFromUserDefaults(){
let defaults = NSUserDefaults.standardUserDefaults()
let long= defaults.doubleForKey("longitudeNameKey")
let lat = defaults.doubleForKey("latitudeNameKey")
println("\(long)")
println("\(lat)")
//You got the coordinates that you lost after terminating now load the coordinates as annotation to mapview
}
You should set new coordinates and terminate application ..notice the coordinates..now again reopen your application ..now you get again those see on the log
P.S code not tested and should change according to your application architecture...only take it as a reference.
Here is the demo project i set up for you
https://drive.google.com/open?id=0B6dTvD1JbkgBRnN2QllWWlJqd0E&authuser=0