gpt4 book ai didi

ios - 在谷歌地图上放置公交车站标记

转载 作者:行者123 更新时间:2023-11-29 01:10:18 25 4
gpt4 key购买 nike

我无法在我的谷歌地图应用程序中放置靠近我的公交车站标记。

假设我住在纽约市,我想要在我的谷歌地图上标记所有公交车站。但是,我真的不知道如何获取我当前城市(纽约)和地点的所有公交车站数据上面有一个选择器。我尝试了 AppCoda 教程,它只给了我自定义搜索的标记

此处:http://www.appcoda.com/google-maps-api-tutorial/

有什么方法可以修改它的“MapTask.Swift”代码以获取我附近的所有公交车站并在每个公交车站放置选择器?

这是 MapTask.Swift

import UIKit
import CoreLocation
import SwiftyJSON

class MapTask: NSObject {

let baseURLGeocode = "https://maps.googleapis.com/maps/api/geocode/json?"

var lookupAddressResults: Dictionary<NSObject, AnyObject>!

var fetchedFormattedAddress: String!

var fetchedAddressLongitude: Double!

var fetchedAddressLatitude: Double!

override init() {
super.init()
}

func geocodeAddress(address: String!, withCompletionHandler completionHandler: ((status: String, success: Bool) -> Void)) {
if let lookupAddress = address {
var geocodeURLString = baseURLGeocode + "address=" + lookupAddress
geocodeURLString = geocodeURLString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!

let geocodeURL = NSURL(string: geocodeURLString)

dispatch_async(dispatch_get_main_queue(), { () -> Void in
let geocodingResultsData = NSData(contentsOfURL: geocodeURL!)

let dictionary: Dictionary<NSObject, AnyObject> = try!NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers) as! Dictionary<NSObject, AnyObject>

// Get the response status.
let status = dictionary["status"] as! String

if status == "OK" {
let allResults = dictionary["results"] as! Array<Dictionary<NSObject, AnyObject>>
self.lookupAddressResults = allResults[0]

print("The result is : \(dictionary)")

// Keep the most important values.
self.fetchedFormattedAddress = self.lookupAddressResults["formatted_address"] as! String
let geometry = self.lookupAddressResults["geometry"] as! Dictionary<NSObject, AnyObject>
self.fetchedAddressLongitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lng"] as! NSNumber).doubleValue
self.fetchedAddressLatitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lat"] as! NSNumber).doubleValue

completionHandler(status: status, success: true)
}
else {
completionHandler(status: status, success: false)
}
})
}
else {
completionHandler(status: "No valid address.", success: false)
}
}

}

最佳答案

您需要使用 type 调用地点搜索设置为 bus_station 以将返回限制为该特定类型。 response将返回 results 及其详细信息,您可以使用这些详细信息来设置标记。

关于ios - 在谷歌地图上放置公交车站标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35839522/

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