通过短信发送当前位置 [英] Send current location through an SMS

查看:120
本文介绍了通过短信发送当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的应用程序能够通过短信将其当前GPS位置发送至预先输入的电话号码。

我现在有我的代码,只能在应用程序中调出一个短信窗口,在该窗口中我可以在接收号码和主体中编辑。我想知道的是我如何获得这个机构的当前位置,以便通过短信发送?无法弄清楚。



这是我的代码关于SMS功能的样子。



<$ p (IBAction)sendInAppSMS:(id)sender
{
MFMessageComposeViewController * controller = [[[MFMessageComposeViewController alloc] init] autorelease]; $ p $
if([MFMessageComposeViewController canSendText])
{
controller.body = @Alarm !,打电话给发件人号码!
controller.recipients = [NSArray arrayWithObjects:@phonenumber1,@phonenumber2,nil];
[self presentModalViewController:controller animated:YES];
}
}


解决方案

首先在您的项目中添加核心位置框架。并调用此方法来查找当前位置。

$ $ p $ - (IBAction)sendInAppSMS:(id)sender
{
MFMessageComposeViewController * controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
CLLocation * location = [self findCurrentLocation];
CLLocationCoordinate2D coordinae = [位置坐标];
controller.body = [[NSString alloc] initWithFormat:@Alarm !,调用发信人号码的纬度:%f经度:%f,coordinae.latitude,coordinae.longitude]; ;
controller.recipients = [NSArray arrayWithObjects:@phonenumber1,@phonenumber2,nil];
[self presentModalViewController:controller animated:YES];



- (CLLocation *)findCurrentLocation
{

CLLocationManager * locationManager = [[CLLocationManager alloc] init];
if([locationManager locationServicesEnabled])
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
}

CLLocation * location = [locationManager location];
CLLocationCoordinate2D坐标= [位置坐标];
返回地点;

}


I'm trying to get my app to be able to send its current GPS location through an SMS to a preentered phone number.

I have my code right now that only brings up an SMS window inside the app in which I can edit in the receiving number and a body. What I am wondering is how I get the current location in this body so it can be sent through the SMS? Can't figure it out.

This is how my code looks right now regarding the SMS function.

-(IBAction) sendInAppSMS:(id) sender
{
    MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"Alarm!, call the senders number!";
        controller.recipients = [NSArray arrayWithObjects:@"phonenumber1", @"phonenumber2", nil];
        [self presentModalViewController:controller animated:YES];
    }
}

解决方案

Firstly add core location framework in Your Project. and call this method for finding current location.

 -(IBAction) sendInAppSMS:(id) sender
    {
        MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
        if([MFMessageComposeViewController canSendText])
        {
            CLLocation *location=[self findCurrentLocation];
            CLLocationCoordinate2D coordinae=[location coordinate];
            controller.body =[[NSString alloc] initWithFormat:@" Alarm!, call the senders number with latitude:%f longitude:%f",coordinae.latitude,coordinae.longitude]; ;
            controller.recipients = [NSArray arrayWithObjects:@"phonenumber1", @"phonenumber2", nil];
            [self presentModalViewController:controller animated:YES];
        }
    }

-(CLLocation*)findCurrentLocation
           {

            CLLocationManager *locationManager = [[CLLocationManager alloc] init];
            if ([locationManager locationServicesEnabled])
            {
                locationManager.delegate = self; 
                locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
                locationManager.distanceFilter = kCLDistanceFilterNone; 
                [locationManager startUpdatingLocation];
            }

            CLLocation *location = [locationManager location];
            CLLocationCoordinate2D coordinate = [location coordinate];
         return location;

    }

这篇关于通过短信发送当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆