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

Error using performSegueWithIdentifier Swift 2.1
Twitter does not return email id after whitelisting in iOS
Delphi 10 Seattle missing libsqlib.a
How to convert date like \/Date(1440156888750-0700)\/ to something that Swift can handle?
Calling Class level code inside block crashes objective c
How to add number of rows in section dynamically in tableview? [closed]
iOS Network Connection Failure Policy suggestions
TTTAttributedLabel link font changing when UIAlertView presents
tell an array to hold instances of an array?
Add Vibrancy effect to custom UIButton?
Image buffer display order with VTDecompressionSession
What is that? Cell or Table? [closed]
Setting up proxy server on iPhone
iOS/FBSDK - FBSDKProfile is nil on device, works fine on simulator
NSMutableAttributedString check nil value [duplicate]
How to use cocoapods with playground?

Categories

HOME
asp.net-mvc
android-sqlite
graylog2
afp
stack
stripe-payments
asp.net-mvc-3
struts2-jquery
android-vision
overloading
cross-compiling
frequency
editor
jquery-jtable
scale
deserialization
orchardcms-1.10
ssrs-tablix
countdown
durandal-2.0
rational
gitlab-ci-runner
sfsafariviewcontroller
revitpythonshell
deadbolt
easendmail
azure-redis-cache
esri
listbox
parallax.js
true-type-fonts
feedly
file-manager
clappr
angular2-databinding
charts.js
inria-spoon
nav
joe-editor
otroslogviewer
runc
tibco-ems
psychopy
maven-jetty-plugin
freecodecamp
rating-system
ewsjavaapi
notimplementedexception
ctl
fido
typesetting
manual
itertools
jvm-arguments
db2400
sqlite-net
android-alertdialog
gwt-material-design
surroundscm
ispconfig
ipopt
rails-console
coldfusion-11
data-fitting
balsamiq
jstorm
angularjs-filter
mars
uiswitch
okuma
xlform
asp.net-webpages
skrollr
wgs84
metalkit
samsung-gear
ssha
jedi
uikeyboard
sample-data
min3d
reactive-cocoa-3
catalina.out
eventmachine
requiredfieldvalidator
dotliquid
blazeds
array-address
mod-python
broadcom
flash-cs4
wow64
route-me
godaddy-api
sizzle
hiphop
program-files
duplicate-data
blackberry-jde
cassandra-0.7
wmd
queryanalyzer
coords
drwatson
68hc11
newsgroup
metaphone

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