ios


Change coordinate of map (MapKit)


I want change the location of my map with personnal coordonate.
(when I say "personnal", is not the "user location" but just random coordonate).
This is my MapView Controller :
class MapSubViewController: UIViewController {
#IBOutlet weak var mapView: MKMapView!
let regionRadius: CLLocationDistance = 1000
override func viewDidLoad() {
super.viewDidLoad()
self.mapLocationUpdate(70.0, longitude: 70.0, title: "")
}
func mapLocationUpdate(latitude: Double, longitude: Double, title: String) {
let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
self.centerMapOnLocation(location, title: title)
}
func centerMapOnLocation(location: CLLocationCoordinate2D, title: String) {
let coordinateRegion = MKCoordinateRegion(center: location, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(coordinateRegion, animated: false)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = title
self.mapView.addAnnotation(annotation)
}
}
I tell my function "mapLocationUpdate" when i want change the location of my map :
Here for example :
func addMapView(xPosition: Double, yPosition: Double, title: String) {
self.mapSubViewController = (self.storyboard!.instantiateViewControllerWithIdentifier("MapSubViewController") as? MapSubViewController)!
self.mapSubViewController.mapLocationUpdate(xPosition, longitude: yPosition, title: clubName)
[...]
}
My app crash when the line "self.mapSubViewController.mapLocationUpdate(...)" is executed. When it's the "viewDidLoad" of the controller who tell the function "mapLocationUpdate", the app not crash.
I think it's because the map location cannot be change in the code after the map charged.
How i can do ?
Sorry for my english, I do my best :-) !
Thx !
In order to set a custom location on a map you should to something similar to this:
let pLat = 43.6109200
let pLong = 3.8772300
let center = CLLocationCoordinate2D(latitude: pLat, longitude: pLong)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)

Related Links

Custom Class View for UIButton
dispatch task into queue in order to run the task in another thread [duplicate]
How to compare PHAsset to UIImage
compiler error use custom shader on a geometry
ABNewPersonViewController does not dismiss the keyboard
Is it useful to create two concurrent queues in IOS?
How to pre-fill email account in google-oauth2 for iOS API
Twitter search api text field value is truncated
How to install root certificate inside iOS app, so it will be trusted when open URL from UIWebView?
JSon and Ambiguos use of subscript
get remote push notification message in background in iOS
Why can't I bold just part of a string in Swift with NSMutableString?
Swift - WebView doesn't detect swipes when loading
Interstitial DFP ad doesn't fill the screen
Q:UITableView scrollview delegate method did not pass the special code
ios Xcode storyboard compact not working

Categories

HOME
elastic-beanstalk
wix
google-apis-explorer
dicom
weight
xquery
logback
google-adwords
wget
activerecord
silverlight
cytoscape.js
highlight
group-by
scale
next
ghost-blog
windows-applications
deadbolt
padding
smallbasic
mathdotnet
rrd
flexjs
json-c
apache-commons-httpclient
blockui
bcel
confirm
h5py
subscription
logicblox
tern
powerpc
kendo-chart
wrk
html-lists
mspgcc
angular-directive
masspay
surroundscm
olingo
coldfusion-11
cglib
file-import
balsamiq
rsh
formatter
jca
strace
greenfoot
sejda
phone-number
perfview
mailx
gem5
android-print-framework
genexus-gam
windows-universal
iscroll4
sqlhelper
ratingbar
symfony-2.5
catalina.out
datacontractserializer
nitrogen
blazeds
acts-as-taggable-on
notifyicon
resolver
emitmapper
zephir
sugar.js
mms-gateway
angularjs-module
godaddy-api
sizzle
northwind
blackberry-cascades
headless-browser
lungojs
self-organizing-maps
stumbleupon
dired
duplicate-data
remote-control
clipboard-pictures
ants

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App