我在我的应用程序中使用适用于 iOS 的 Google Maps SDK。我需要在 map 移动时获取地址。但是 idleAtCameraPosition 没有被触发。
func vwGMap(vwGMap: GMSMapView!, idleAtCameraPosition position: GMSCameraPosition!) {
print("changed position: \(vwGMap.camera.target)")
}
我在 viewDidLoad() 中添加了委托(delegate)
vwGMap.delegate = self
并声明 map View
@IBOutlet var vwGMap: GMSMapView!
为什么 idleAtCameraPosition 没有被触发?
完整代码
class MapViewController: BaseViewController,CLLocationManagerDelegate, UISearchBarDelegate ,GMSMapViewDelegate, LocateOnTheMap,GMSAutocompleteFetcherDelegate {
@IBOutlet var marker: UIImageView!
@IBOutlet var fromaddress: kTextFiledPlaceHolder!
@IBOutlet var toaddress: kTextFiledPlaceHolder!
@IBOutlet var fromdummy: kTextFiledPlaceHolder!
@IBOutlet var vwGMap: GMSMapView!
var searchResultController: SearchResultsController!
var resultsArray = [String]()
var gmsFetcher: GMSAutocompleteFetcher!
var locationManager = CLLocationManager()
var didFindMyLocation = false
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.addSlideMenuButton()
//Location Manager code to fetch current location
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
vwGMap.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
searchResultController = SearchResultsController()
searchResultController.delegate = self
gmsFetcher = GMSAutocompleteFetcher()
gmsFetcher.delegate = self
}
//Location Manager delegates
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude:(location?.coordinate.longitude)!, zoom:16)
vwGMap.animate(to: camera)
CATransaction.begin()
CATransaction.setValue(5, forKey: kCATransactionAnimationDuration)
vwGMap.animate(toViewingAngle: 40)
vwGMap.animate(toBearing: 80)
//vwGMap.animate(toZoom: 18)
CATransaction.commit()
vwGMap.settings.myLocationButton = true
vwGMap.isMyLocationEnabled = true
vwGMap.delegate = self
self.vwGMap.addSubview(toaddress)
self.vwGMap.addSubview(fromdummy)
self.vwGMap.addSubview(marker)
self.locationManager.stopUpdatingLocation()
}
public func didFailAutocompleteWithError(_ error: Error) {
// resultText?.text = error.localizedDescription
}
/**
* Called when autocomplete predictions are available.
* @param predictions an array of GMSAutocompletePrediction objects.
*/
public func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
//self.resultsArray.count + 1
print(predictions)
for prediction in predictions {
if let prediction = prediction as GMSAutocompletePrediction!{
self.resultsArray.append(prediction.attributedFullText.string)
}
}
self.searchResultController.reloadDataWithArray(self.resultsArray)
// self.searchResultsTable.reloadDataWithArray(self.resultsArray)
print("check")
print(resultsArray)
}
func locateWithLongitude(_ lon: Double, andLatitude lat: Double, andTitle title: String) {
DispatchQueue.main.async { () -> Void in
let position = CLLocationCoordinate2DMake(lat, lon)
let marker = GMSMarker(position: position)
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 10)
// self.vwGMap.camera = camera
//
// marker.title = "Address : \(title)"
// marker.map = self.vwGMap
CATransaction.begin()
CATransaction.setValue(5, forKey: kCATransactionAnimationDuration)
self.vwGMap.animate(to: camera)
CATransaction.commit()
}
}
func locate(_ lon: Double, andLatitude lat: Double) {
DispatchQueue.main.async { () -> Void in
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 10)
// self.vwGMap.camera = camera
//
// marker.title = "Address : \(title)"
// marker.map = self.vwGMap
CATransaction.begin()
CATransaction.setValue(5, forKey: kCATransactionAnimationDuration)
self.vwGMap.animate(to: camera)
CATransaction.commit()
}
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// let placeClient = GMSPlacesClient()
//
//
// placeClient.autocompleteQuery(searchText, bounds: nil, filter: nil) {(results, error: Error?) -> Void in
// // NSError myerr = Error;
// print("Error @%",Error.self)
//
// self.resultsArray.removeAll()
// if results == nil {
// return
// }
//
// for result in results! {
// if let result = result as? GMSAutocompletePrediction {
// self.resultsArray.append(result.attributedFullText.string)
// }
// }
//
// self.searchResultController.reloadDataWithArray(self.resultsArray)
//
// }
print(searchText)
self.resultsArray.removeAll()
gmsFetcher?.sourceTextHasChanged(searchText)
}
func mapView(_ mapView: GMSMapView, idleAtCamera position: GMSCameraPosition) {
print("changed position")
}
}
最佳答案
确保将类扩展到 GMSMapViewDelegate。
示例代码:
class Class-name : UIViewController,GMSMapViewDelegate
更改 viewDidLoad 中的代码:
vwGMap = GMSMapView()
vwGMap.delegate = self
将此方法用于点击标记事件。
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
}
如果 map View 是滚动的:
func mapView(_ mapView: GMSMapView, idleAt cameraPosition: GMSCameraPosition) {
print("map scrolled.")
}
关于ios - 未触发 GMSMapViewDelegate idleAtCameraPosition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43095985/
请帮助我理解范围运算符...和..之间的区别,作为Ruby中使用的“触发器”。这是PragmaticProgrammersguidetoRuby中的一个示例:a=(11..20).collect{|i|(i%4==0)..(i%3==0)?i:nil}返回:[nil,12,nil,nil,nil,16,17,18,nil,20]还有:a=(11..20).collect{|i|(i%4==0)...(i%3==0)?i:nil}返回:[nil,12,13,14,15,16,17,18,nil,20] 最佳答案 触发器(又名f/f)是
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我有一个rubyonrails应用程序。我按照facebook的说明添加了一个像素。但是,要跟踪转化,Facebook要求您将页面置于达到预期结果时出现的转化中。即,如果我想显示客户已注册,我会将您注册后转到的页面作为成功对象进行跟踪。我的问题是,当客户注册时,在我的应用程序中没有登陆页面。该应用程序将用户带回主页。它在主页上显示了一条消息,所以我想看看是否有一种方法可以跟踪来自Controller操作而不是实际页面的转化。我需要计数的Action没有页面,它们是ControllerAction。是否有任何人都知道的关于如何执行此操作的gem、文档或最佳实践?这是进入布局文件的像素
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
我有一个super简单的脚本,它几乎包含了FayeWebSocketGitHub页面上用于处理关闭连接的内容:ws=Faye::WebSocket::Client.new(url,nil,:headers=>headers)ws.on:opendo|event|p[:open]#sendpingcommand#sendtestcommand#ws.send({command:'test'}.to_json)endws.on:messagedo|event|#hereistheentrypointfordatacomingfromtheserver.pJSON.parse(event.d
我想写一点“Deprecate-It”库并经常使用“method_added”回调。但是现在我注意到在包含模块时不会触发此回调。是否有任何回调或变通方法,以便在某些内容包含到自身时通知类“Foobar”?用于演示的小Demo:#IncludingModulswon'ttriggermethod_addedcallbackmoduleInvisibleMethoddefinvisible"Youwon'tgetacallbackfromme"endendclassFoobardefself.method_added(m)puts"InstanceMethod:'#{m}'addedto'
我看到有关未找到文件min.map的错误消息:GETjQuery'sjquery-1.10.2.min.mapistriggeringa404(NotFound)截图这是从哪里来的? 最佳答案 如果ChromeDevTools报告.map文件的404(可能是jquery-1.10.2.min.map、jquery.min.map或jquery-2.0.3.min.map,但任何事情都可能发生)首先要知道的是,这仅在使用DevTools时才会请求。您的用户不会遇到此404。现在您可以修复此问题或禁用sourcemap功能。修复:获取文