如何获得Android的纬度,经度和地址 [英] How to get latitude, longitude and address in android

查看:166
本文介绍了如何获得Android的纬度,经度和地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  如何通过手机短信检索GPS位置

我想提出的是要像这样一个Android应用程序:
当用户键入包含如findmyphone之类的东西(它不会给其他正常的短信回应)到正在运行的应用程序的手机短信,应用程序将自动响应与纬度,经度的数量和在运行应用程序的电话的地址。

I am making an android application that is going to act like this: When a user types a text message containing for example "findmyphone" or anything like that (it will not respond to other normal text messages) to the phone that is running the application, the application will automatically respond to that number with latitude, longitude and the address of the phone that is running the application.

我还需要一个按钮对其进行测试。一旦用户presses测试按钮,纬度,经度和地址将出现在2文本框,纬度和经度于一体,并在另外一个的地址。在此先感谢这么多!这是我到目前为止有:

I also need a button for testing it. And once the user presses the "Test" button, the latitude, longitude and address will appear in 2 textboxes, latitude and longitude in one, and the address in the other one. Thanks SO much in advance! This is what I have so far:

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class FindAndroidActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button Nextbutton1, Nextbutton2, TestLocationService;
TextView Cordinates, Adress, FindAndroid;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Nextbutton1 = (Button)findViewById(R.id.Nextbutton1);
    Nextbutton1.setOnClickListener(this);
}
public void onClick(View src) {
    switch (src.getId()) {
    case R.id.Nextbutton1:
        setContentView(R.layout.setup);
        Nextbutton2 = (Button)findViewById(R.id.Nextbutton2);
        Nextbutton2.setOnClickListener(this);
        TestLocationService = (Button)findViewById(R.id.TestLocationService);
        TestLocationService.setOnClickListener(this);
        break;
    case R.id.Nextbutton2:
        setContentView(R.layout.main);
        break;
    case R.id.TestLocationService:
        break;
    }
}
    public Address getAddressForLocation(Context context, Location location) throws IOException {

        if (location == null) {
            return null;
        }
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        int maxResults = 1;

        Geocoder gc = new Geocoder(context, Locale.getDefault());
        List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults);

        if (addresses.size() == 1) {
            return addresses.get(0);
        } else {
            return null;
        }
}

}

推荐答案

我不会放弃任何东西的详细说明,因为你可以做一个谷歌搜索或搜索计算器为您最需要的信息。

I will not give detailed instructions on anything because you can do a google search or search StackOverflow for most information that you need.

要获得一个位置,你可以使用 的LocationManager 并调用 requestLocationUpdates 。有很多教程解释如何做到这一点。

To get a location, you would use LocationManager and invoke requestLocationUpdates. There are plenty of tutorials that explain how to do this.

要收到一条短信,你会需要一个 广播接收器 在你的清单类似如下声明:

To receive an sms, you would need a BroadcastReceiver declared in your Manifest like the following:

<receiver android:name=".SmsReceiver">
                    <intent-filter>
                        <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
                    </intent-filter>
                </receiver>

在此receivery你会使用 SmsMessage 类来获得从SMS必要的信息。

Within this receivery you would use the SmsMessage class to get the necessary info from the sms.

然后发短信回来,你会使用 SmsManager 并调用 sendTextMessage

Then to send an sms back, you would use SmsManager and invoke sendTextMessage.

BUT :结果
你真的需要做自己的工作。这也是很好的注意,有在市场上已经电话定位器应用一吨,所以这可能不是一个欢颜应用为你做。

BUT:
You really need to do the work on your own. It's also good to note that there are a TON of phone locator applications on the Market already, so this might not be a worthwile app for you to make.

再次,你可以搜索计算器或谷歌以找出如何做到这一点你需要每一件事情。

And again, you can search stackoverflow or Google to find out how to do each thing that you're needing.

如果你没有做任何实际的Andr​​oid编程(因为你说你使用的应用程序的发明者),那么你需要看的开发人员指南

And if you haven't done any actual Android programming (since you said you used app inventor), then you need to look at the Developer's Guide

这篇关于如何获得Android的纬度,经度和地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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