gpt4 book ai didi

swift - 在 swift 中使用 google api 在 Google map 中添加新地点

转载 作者:行者123 更新时间:2023-11-30 14:04:43 25 4
gpt4 key购买 nike

我需要在谷歌地图中添加一个新位置。我知道我需要创建一个包含 JSON 格式的新地点信息的请求,我需要的是如何传递该请求。提前致谢。

var dictionaryObject: NSDictionary = [
"location": [
"lat": "\(latitude)",
"lng": "\(longitude)"
],
"accuracy": 50,
"name": "\(nameField.text)",
"phone_number": "\(phoneNoField.text)",
"address": "\(addressField.text)",
"types": "\(typeField.text)",
"website": "\(websiteField.text)",
"language": "en-AU"
]

var url: NSURL = NSURL(string: "https://maps.googleapis.com/maps/api/place/add/json?key=API-KEY")!
var request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
var error: NSError?

var theJSONData = NSJSONSerialization.dataWithJSONObject(
dictionaryObject ,
options: NSJSONWritingOptions(0),
error: nil)
var theJSONText = NSString(data: theJSONData!,
encoding: NSASCIIStringEncoding)
println((theJSONData))
//request.HTTPBody = theJSONText?.dataUsingEncoding(NSUTF8StringEncoding)
request.HTTPBody = theJSONData
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
var parseError: NSError?
var responseObject = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &parseError) as? NSDictionary
println((responseObject))

}

最佳答案

最简单的方法是使用 iOS 版 Google Places API 中的 addPlace 方法。请参阅Place Add guide在 Google Developers 网站上,该网站上有 Swift 和 Objective-C 的代码示例。

关于swift - 在 swift 中使用 google api 在 Google map 中添加新地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com