swift - Fetching nearby places using google maps -


am trying implement find nearby places of current location using google maps. have created project in google developer console , got 'ios apikey' , 'server apikey'. enabled google places api , google maps sdk ios. below code find out near places.

func fetchplacesnearcoordinate(coordinate: cllocationcoordinate2d, radius: double, name : string){     var urlstring = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=\(apiserverkey)&location=\(coordinate.latitude),\(coordinate.longitude)&radius=\(radius)&rankby=prominence&sensor=true"     urlstring += "&name=\(name)"      urlstring = urlstring.stringbyaddingpercentescapesusingencoding(nsutf8stringencoding)!     println(urlstring)     if placestask.taskidentifier > 0 && placestask.state == .running {         placestask.cancel()      }     uiapplication.sharedapplication().networkactivityindicatorvisible = true     placestask = session.datataskwithurl(nsurl(string: urlstring)!) {data, response, error in         println("inside.")         uiapplication.sharedapplication().networkactivityindicatorvisible = false         if let json = nsjsonserialization.jsonobjectwithdata(data, options:nil, error:nil) as? nsdictionary {             if let results = json["results"] as? nsarray {                 rawplace:anyobject in results {                     println(rawplace)                     self.results.append(rawplace as! string)                 }             }         }             self.placestask.resume()     } } 

the passed coordinate current location's coordinate. if execute above code, nothing happening generated url valid one. if put url in google getting correct results. nothing displaying in app. please me resolve this. , please let me know wrong!!!

you add places results array, have done update mapview, example, adding markers mapview.

sample code add marker mapview:

   let returnedplaces: nsarray? = jsonresult["results"] as? nsarray    if returnedplaces != nil {             index in 0..<returnedplaces!.count {                   if let returnedplace = returnedplaces?[index] as? nsdictionary {                         var placename = ""                        var latitude = 0.0                        var longitude = 0.0                         if let name = returnedplace["name"] as? nsstring {                            placename = name string                        }                         if let geometry = returnedplace["geometry"] as? nsdictionary {                            if let location = geometry["location"] as? nsdictionary {                                  if let lat = location["lat"] as? double {                                             latitude = lat                                  }                                   if let lng = location["lng"] as? double {                                            longitude = lng                                   }                             }                        }                         let marker = gmsmarker()                        marker.position = cllocationcoordinate2dmake(latitude, longitude)                        marker.title = placename                        marker.map = self.mapview                 }            }    } 

you can see this tutorial how nearby places google maps in swift.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -