0

This json is loading restaurants by taking state and city of USA and showing it on Map with Markers along with address and restaurant name. This App works on Simulator but doesn't run on iPhones and iPods when it searches the restaurant.

            do{
                var strData = NSString(data: data!, encoding: NSUTF8StringEncoding)
                var decodedData: NSData?
                if strData == nil{
                    strData = NSString(data: data!, encoding: NSASCIIStringEncoding)
                    decodedData = strData!.dataUsingEncoding(NSUTF8StringEncoding)
                }else {

                    decodedData = data;
                }
                let json = try NSJSONSerialization.JSONObjectWithData(decodedData!, options:.AllowFragments)

                let annotationsToRemove = self.mapView.annotations.filter { $0 !== self.mapView.userLocation }
                self.mapView.removeAnnotations( annotationsToRemove )

                for dict in json as! [NSDictionary]{
                    self.names.append(dict["name"] as! String)
                    self.address.append(dict["address"] as! String)
                    self.label.append(dict["label"] as! String)

             //For Loop

                    // to display address
                        for googleadd in self.address {

                        // to display restaurant name
                       for googlename in (self.names) {
                            let annotationTitle: String = googlename;

                        var geocoder = CLGeocoder()
                        geocoder.geocodeAddressString(googleadd, completionHandler: {(placemarks, error) -> Void in
                            if let placemark = placemarks?[0] as? CLPlacemark? {

                                if placemark == nil{
                                    return
                                }


                                    if let coordinate = placemark?.location?.coordinate {

                                    let anotation = MKPointAnnotation()


                                   anotation.coordinate = coordinate



                                       anotation.title = googlename



                                   anotation.subtitle = googleadd

                                    self.mapView.addAnnotation(anotation)
                                    self.mapView.setCenterCoordinate(coordinate, zoomLevel: 12, animated: true)   

                                }
                            }


             })
Kada
  • 63
  • 8
  • I suggest getting a crash log off the device, symbolicating it, and posting the stack trace for the problem thread. – Phillip Mills Aug 28 '16 at 18:56
  • You could also run your app through Xcode's Instruments and try to see if it eats too much memory or anything similar. – Eric Aya Aug 29 '16 at 09:15

0 Answers0