如何使应用显示用户当前位置的地图,然后将其引导到设置的位置?

时间:2018-07-05 15:09:41

标签: ios swift mapkit

我目前正在使用的代码是:

import UIKit
import MapKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    openMapForPlace()
}

func openMapForPlace() {
    let coordinate = CLLocationCoordinate2DMake(-37.688607,144.890787)
    let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, addressDictionary:nil))
    mapItem.name = "Gladstone Park Secondary College"
    mapItem.openInMaps(launchOptions: [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving])
}

它唯一显示的是一张澳大利亚地图,并将其输出-无法从第4个角插入合法归属。

2 个答案:

答案 0 :(得分:2)

尝试此代码,我为您服务。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

   if userLocation != nil {

    locationManager.stopUpdatingLocation()

    mapView.camera = GMSCameraPosition(target: selectedCoordinate!.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

 } else if let location = locations.first {

         mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

         locationManager.stopUpdatingLocation()
   }
}

答案 1 :(得分:0)

尝试

import requests

cookies = {
    'JSESSIONID': 'V4LKVAGE723K5PGBRA8AVENT943QJJ9H7Q8DQ3RF9AKFUKHMQMVTKJJKD1I020005K000000.JCWSV03_001',
    'visid_incap_763612': 'vh9PZJxzSX+IQrGov+h+4xvvBFsAAAAAQUIPAAAAAACfECPoFSsLL9R6RNgb2BNn',
    'incap_ses_677_763612': 'S7ABVEJemmrXkVaexDBlCYKiPVsAAAAAZdhOPF1KvRtJcnKmfT3GRA==',
    '___utmvmOKuDywS': 'rKJenOqgmrg',
    '___utmvbOKuDywS': 'sZe XmcOOalV: ltS',
}

headers = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
    'Origin': 'http://www.customs.go.jp',
    'Upgrade-Insecure-Requests': '1',
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Referer': 'http://www.customs.go.jp/toukei/srch/jccht00p.htm',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'en-US,en;q=0.9,en-CA;q=0.8',
}

data = [
  ('CW_SEARCHID', 'JCCHT03S'),
  ('CW_JAPANKBN', '2'),
  ('CW_IMPKBN', '2'),
  ('CW_CARGOKBN', ''),
  ('CW_SUMKBN', ''),
  ('CW_SPCODE', ''),
  ('CW_SPNAME', ''),
  ('CW_YMSORTKBN', ''),
  ('CW_SISUKBN', ''),
  ('CW_SENKIKBN', ''),
  ('CW_HKKBN', ''),
  ('CW_YMKBN', '1'),
  ('CW_KI', ''),
  ('CW_SYY', '2017'),
  ('CW_EYY', ''),
  ('CW_SMM', '2'),
  ('CW_EMM', ''),
  ('CW_HSKBN', '2'),
  ('CW_HSCODE', '271111'),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSCODE', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_HSNAME', ''),
  ('CW_KUNIKBN', '1'),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNICODE', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_KUNINAME', ''),
  ('CW_ZMKBN', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMCODE', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_ZMNAME', ''),
  ('CW_MEISAICNT', '200'),
]

response = requests.post('http://www.customs.go.jp/JCWSV03/servlet/JCWSV03', data=data)

from bs4 import BeautifulSoup as bs
soup = bs(response.text, 'html.parser')
country = [x.text for x in soup.find_all('td', 'left_sTotal')[0::3]]
quantity = [x.text for x in soup.find_all('td', 'sTotal')[1::6]]
value = [x.text for x in soup.find_all('td', 'sTotal')[2::6]]
total_list = [list(x) for x in zip(country,quantity,value)]

import pandas as pd
df = pd.DataFrame(total_list, columns = ('country', 'quantity', 'value'))
df.head()