5588葡京线路Location and Mapping

iOS9每当MapKit和Core Location中益了累累新特性.
根本出几只地方:

题材链接:

  TP

  • 应用内地图新的点击弹出页面.
  • 苹果地图中几种植交通器的线图.
  • 预估乘坐四通八达器到所急需的时间.
  • Core Location利用Single location updates来定位.
    首先iOS9遭之地形图中可以显得罗盘 比例尺交通状况

题解:

    从而说,超显眼的数码范围啊。

  很强烈我们于每个P的区间都是要有k个站被bus停留,然后考虑更换的言语应该是将当时k个站里的某部bus往前头挪,那么换也杀显了,n的限非常怪,所以直接上矩阵。

mapshow.png

代码:

#define Troy 

#include <bits/stdc++.h>

using namespace std;

inline int read(){
    int s=0,k=1;char ch=getchar();
    while(ch<'0'|ch>'9')    ch=='-'?k=-1:0,ch=getchar();
    while(ch>47&ch<='9')    s=s*10+(ch^48),ch=getchar();
    return s*k;
}

const int N=129,mod=30031;

int n,k,p,BGM,stk[N],m;

struct Matrix{
    int a[N][N];
    Matrix(){memset(a,0,sizeof(a));}
    inline void evoid(){
        for(int i=0;i^m;++i)
            a[i][i]=1;
    }
    inline friend Matrix operator *(const Matrix &x,const Matrix &y){
        Matrix c;
        for(int i=0;i^m;++i)
            for(int j=0;j^m;++j)
                for(int k=0;k^m;++k)
                    c.a[i][j]=(c.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
        return c;
    }
    inline friend Matrix operator ^(Matrix x,int b){
        Matrix ret;ret.evoid();
        while(b){
            if(b&1)ret=ret*x;
            b>>=1;x=x*x;
        }return ret;
    }
};

inline bool move_to(int to,int from){
    from^=1<<p-1;
    from<<=1;
    int deta=from^to;
    return (deta&(-deta))==deta;
}

int main(){
    n=read(),k=read(),p=read();
    register int i,j;    
    for(i=(1<<p-1);i^(1<<p);++i){
        int x=i;
        for(j=0;x;x^=(x&(-x)),++j);
        if(j==k){
            if(i==(1<<p)-(1<<p-k))
                BGM=m;
            stk[m++]=i;
        }
    }
    Matrix ans,t;
    ans.a[BGM][0]=1;
    for(i=0;i^m;++i)
        for(j=0;j^m;++j){
                t.a[i][j]=move_to(stk[j],stk[i]);
        }
    ans=(t^(n-k))*ans;
    printf("%d\n",ans.a[BGM][0]);
}

 

来得比例尺的法很粗略:

mapView.showsScale = true

早先pinColor颜色只发生吉庆、绿与紫色.iOS9遭受之所以pinTintColor来替pinColor从而得以于定义颜色:

annotationView!.pinTintColor = UIColor(red:0.5,  green:0.88, blue:0, alpha:1)

先我们定制一个点击大头针的弹来界面需要用你定制的界面上加到annotation
View,而iOS9如果之移得非常简单:MKAnnotationView增加了detailCalloutAccessoryView的性质,使定制页面更加有利于,我们用Xib定义一个CoffeeShopPinDetailView.xib页面:

mapxibview.png

填补加时只是需要:

let detailView = UIView.loadFromNibNamed(identifier) as! CoffeeShopPinDetailView
detailView.coffeeShop = annotation.coffeeshop
annotationView!.detailCalloutAccessoryView = detailView

哪怕完成了打定义界面的丰富:

showview.png

iOS9以前我们要稳位置要创造CLLocationManager并贯彻代理方都调用startUpdatingLocation(),当你得位置后若待调用stopUpdatingLocation()来终止更新位置.如果你不调用stop,就会见一直获得位置信息,超费电.而iOS将其长进为要调用一个方requestLocation()即可.一旦取得你的职务后,只会调用一糟糕代理方,达到省电效果.实现代码:

  lazy var locationManager = CLLocationManager()

    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters

    mapView.showsUserLocation = true 
    if CLLocationManager.authorizationStatus() ==
      .AuthorizedWhenInUse { 
        locationManager.requestLocation()   
    } else {
      locationManager.requestWhenInUseAuthorization()   
    }

// MARK:- CLLocationManagerDelegate
extension ViewController: CLLocationManagerDelegate {
 func locationManager(manager: CLLocationManager,didChangeAuthorizationStatus status: CLAuthorizationStatus) {
 if (status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse) {
 locationManager.requestLocation() }
 } 
func locationManager(manager: CLLocationManager,
 didUpdateLocations locations: [CLLocation]) { currentUserLocation = locations.first?.coordinate
 } 
func locationManager(manager: CLLocationManager,
 didFailWithError error: NSError) {
 print("Error finding location:  + \(error.localizedDescription)")
}
}

本得以描绘来位置5588葡京线路之间的交通连接,方法如下:

  func openTransitDirectionsForCoordinates(coord:CLLocationCoordinate2D) {
    let placemark = MKPlacemark(coordinate: coord,
      addressDictionary: coffeeShop.addressDictionary) 
    let mapItem = MKMapItem(placemark: placemark)  
    let launchOptions = [MKLaunchOptionsDirectionsModeKey:
      MKLaunchOptionsDirectionsModeTransit]  
    mapItem.openInMapsWithLaunchOptions(launchOptions)  
  }

效益如下:

transitmap.png

咱得以测算出点儿个地方之间所花费的大概时间:

  func requestTransitTimes() {
    guard let currentUserLocation = currentUserLocation else {
      return
    }
    let request = MKDirectionsRequest()
    let source = MKMapItem(placemark:
      MKPlacemark(coordinate: currentUserLocation,
        addressDictionary: nil))
    let destination = MKMapItem(placemark:
      MKPlacemark(coordinate: coffeeShop.location,
        addressDictionary: nil))
    request.source = source
    request.destination = destination
    request.transportType = MKDirectionsTransportType.Transit
    let directions = MKDirections(request: request)
    directions.calculateETAWithCompletionHandler { response, error in
      if let error = error {
        print(error.localizedDescription)
      } else {
        self.updateEstimatedTimeLabels(response)
      }
    }
  }

第一创建一个MKDirectionsRequest.然后创造而的当下职务以及所假设达的位置MKMapItem,继而设置MKDirectionsRequest的source、destination和transportType.创建MKDirections来回调出时间.
Girl学iOS100天 第3天 🙂