Как я могу добавить несколько маркеров на карту Google, используя json и swift 4.1?

Несколько маркеров не отображаются на карте Google с использованием Swift 4.1. Я подключаю JSON, и результат отображается на консоли, но как я могу подключиться к широте и долготе с картами Google.

let jsonUrl = URL(string: "http://assetlinkasia.no-ip.biz:8001/hf_tracker/api/userdevices.php?accesskey=12345&user_id=1")            
    if let url = jsonUrl {
        let data = NSData(contentsOf: url)
        if let data = data {
            do{
                let jsonObject = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)                    
                if let object = jsonObject as? [NSString: AnyObject]{
                    if let allDevices = object["data"] as? [[NSString: AnyObject]]{                            
                        print("Successfull")
                        print(allDevices)                            
                    }
                }
            }catch{
                print("Error Eccurred")
            }
        }
    }

и это мой код карты Google здесь:

    let getLongijson = Double("67.0011")
    let getlatijson = Double("24.8607")

    let camera = GMSCameraPosition.camera(withLatitude: getlatijson!, longitude: getLongijson!, zoom: 13.0)

    let mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
    self.view = mapView

   // meanView.addSubview(mapView)

    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: getlatijson!, longitude: getLongijson!)
    marker.infoWindowAnchor = CGPoint(x:0.10, y:0.10)
    marker.title = HeadingName
    marker.snippet = Countory
    marker.icon = UIImage(named: "markers")
    marker.map = mapView

    //User Location
    locationManager.delegate = self
    locationManager.requestWhenInUseAuthorization()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()

   // self.menuFunction()

    mapView.delegate = self

person Rehan Meo    schedule 23.05.2018    source источник
comment
Каков ваш актуальный вопрос?   -  person Dragonthoughts    schedule 23.05.2018
comment
как добавить json с картой google для нескольких маркеров   -  person Rehan Meo    schedule 23.05.2018


Ответы (1)


Попробуй это

Цель-c

     count = (int)locatorObject.LocationList.count; 
     for(int i=0;i< count;i++)
            {
            LocationDetails *locator = locatorObject.LocationList[i];
            CLLocationCoordinate2D position = CLLocationCoordinate2DMake([locator.Lat floatValue],[locator.Long floatValue]);
            GMSMarker *marker = [GMSMarker markerWithPosition:position];
            marker.title = locator.Address;
            marker.map = _googleMapView;
            }

быстро

 for i in 0..<count {
        var locator: LocationDetails? = locatorObject.locationList[i]
        var position: CLLocationCoordinate2D = CLLocationCoordinate2DMake(locator?.lat, locator?.long)
        var marker = GMSMarker(position: position)
        marker.title = locator?.address
        marker.map = googleMapView
    }
person Musavir Parambil    schedule 23.05.2018