Ios 使用Swift在电子邮件中嵌入谷歌地图
我试图做的是构建简单的SOS(帮助我!)应用程序 将有一个按钮调用发送电子邮件表单。 目前,我正处于从设备获取位置的阶段,希望将其嵌入电子邮件中,然后发送到电子邮件地址 我想在发送的邮件中包含谷歌地图的所有已知功能。 如果可能的话,我希望能够在地图上的确切位置标记“X”。 当我已经掌握了位置时,如何做到这一点 我是swift和iOS的新手,因此欢迎提出任何更改设计的建议 到目前为止,我掌握的代码是:Ios 使用Swift在电子邮件中嵌入谷歌地图,ios,swift,google-maps,email,ios8,Ios,Swift,Google Maps,Email,Ios8,我试图做的是构建简单的SOS(帮助我!)应用程序 将有一个按钮调用发送电子邮件表单。 目前,我正处于从设备获取位置的阶段,希望将其嵌入电子邮件中,然后发送到电子邮件地址 我想在发送的邮件中包含谷歌地图的所有已知功能。 如果可能的话,我希望能够在地图上的确切位置标记“X”。 当我已经掌握了位置时,如何做到这一点 我是swift和iOS的新手,因此欢迎提出任何更改设计的建议 到目前为止,我掌握的代码是: // // ViewController.swift // SOSapp // // Cr
//
// ViewController.swift
// SOSapp
//
// Created by Max Segal on 7/22/15.
// Copyright (c) 2015 Max Segal. All rights reserved.
//
import UIKit
import CoreLocation
import MessageUI
class ViewController: UIViewController, CLLocationManagerDelegate, MFMailComposeViewControllerDelegate{
@IBOutlet var statusLabel: UILabel!
let locationManager=CLLocationManager()
var locationString=""
override func viewDidLoad() {
super.viewDidLoad()
if ( MFMailComposeViewController.canSendMail() == false){
var alert=UIAlertController(title: "No email account", message: "No email account - can't send SOS message. Be strong!", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated:true, completion:nil)
exit(0)
}
locationManager.delegate=self
locationManager.desiredAccuracy=kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func sosButtonPressed(sender: UIButton) {
var emailTitle = "SOS message"
var messageBody = "Please help me out! I am here:\n\(locationString)"
var recipient=SosSender.emailAddress
var mc = MFMailComposeViewController()
mc.mailComposeDelegate=self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML:true)
mc.setToRecipients([recipient])
self.presentViewController(mc, animated: true, completion: nil)
statusLabel.text="Sending SOS email to " + SosSender.emailAddress+"\nLocation: " + locationString
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -> Void in
if (error != nil) {
println("Error: " + error.localizedDescription)
return
}
if (placemarks.count > 0) {
let pm = placemarks[0] as! CLPlacemark
self.locationString=self.locationInfoToString(pm)
println("Debug:" + self.locationString)
}else{
println("Error with data")
}
})
}
func locationInfoToString(placemark: CLPlacemark) -> String
{
self.locationManager.stopUpdatingLocation()
return placemark.locality + "\n" + placemark.administrativeArea + "\n" + placemark.country;
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("Error: " + error.localizedDescription)
}
//Email delegate
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
switch result.value {
case MFMailComposeResultCancelled.value:
println("Mail Cancelled")
case MFMailComposeResultSaved.value:
println("Mail Saved")
case MFMailComposeResultSent.value:
println("Mail Sent")
case MFMailComposeResultFailed.value:
println("Mail Failed")
default:
break
}
self.dismissViewControllerAnimated(false, completion: nil)
}
}
谢谢。如果您想捕获设备的当前屏幕,可以参考使用
UIGraphics
。这篇文章对我有何帮助?我想捕获设备的地理位置,而不是屏幕……但你想在应用程序中截取你的谷歌地图,对吗?如果你想捕获设备的当前屏幕,可以参考使用UIGraphics
。这篇文章对我有何帮助?我想捕获地理位置而不是设备屏幕…但你想在应用程序中截取谷歌地图,对吗?