I'm trying to display few markers with settings which I get from remote JSON and local SQLite database. I have marker's name and snippet stored inside JSON and latitude with longitude which are inside the sqlite database. Unfortunately only one marker appears on the map. Should I create another array for markers? How to display markers with loop? Here is the code which display one pin.
import UIKit
var camera = GMSCameraPosition.cameraWithLatitude(53.42854, longitude:14.55281, zoom: 13)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
class MapViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
displayMarkers()
}
func displayMarkers() -> Void
{
let jsonURL: NSURL = NSURL(string: "http://ift.tt/1wvZmXO")!
var dataFromNetwork: NSData = NSData(contentsOfURL: jsonURL)!
let json = JSON(data: dataFromNetwork) //println(json)
var jsonSize = json.count
mapView.myLocationEnabled = true
var marker:GMSMarker = GMSMarker()
for(var i = 0; i < jsonSize; i++)
{
let (resultSet, err) = SD.executeQuery("SELECT * FROM Clubs WHERE ID = ?", withArgs: [i])
if(err != nil)
{
println("SQLite SELECT error!")
}
else
{
for row in resultSet
{
let name = row["Name"]?.asString()
marker.title = name
let latitude = row["Latitude"]?.asDouble()
var markerLatitude: Double = latitude!
let longitude = row["Longitude"]?.asDouble()
var markerLongitude: Double = longitude!
marker.position = CLLocationCoordinate2DMake(markerLatitude, markerLongitude)
let partyName = json[i]["nazwa"].stringValue
marker.snippet = partyName
marker.appearAnimation = kGMSMarkerAnimationPop
}
marker.map = mapView
}
}
self.view = mapView
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Aucun commentaire:
Enregistrer un commentaire