我正在使用<?php
if (isset($_POST['mail-submit'])) {
$hour = trim($_POST['mail-hour']);
$phone = trim($_POST['mail-phone']);
$email = trim($_POST['mail-email']);
$message = trim($_POST['mail-msg']);
if($hour != null && $phone != null && $email != null){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$signal = 'bad';
$msg = 'Invalid email. Please check';
}
else {
$signal = 'ok';
$msg = 'Form submitted';
}
}
else{
$signal = 'bad';
$msg = 'Please fill in all the fields.';
}
$data = array(
'signal' => $signal,
'res-msg' => $msg
);
echo json_encode($data);
}
?>
来获取当前位置,但是却一直没有获取位置
MapKit
答案 0 :(得分:2)
尝试import CoreLocation
,在mLocation
中呼叫viewDidLoad
。
完成mLocation功能后,LocationManager会更新您的位置。
if distance
方法现在每100米更新一次。
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let myLocation = CLLocation()
let locationManager = CLLocationManager()
@IBOutlet weak var latitudeTextField: UITextField!
@IBOutlet weak var longtitudeTextField: UITextField!
override func viewDidLoad(){
super.viewDidLoad()
mLocation()
}
@IBAction func saveCurrentLocation(){
self.latitudeTextField.text = "\\(myLocation.coordinate.latitude)"
self.longtitudeTextField.text = "\(myLocation.coordinate.longitude)"
}
func mLocation(){
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled(){
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations:[CLLocation]){
let newLocation = locations[0]
let distance = myLocation.distance(from: newLocation)
if distance > 100 {
myLocation = newLocation
}
}
}