可能重复纬度,经度和地址:
How to retrieve the GPS location via SMS如何让机器人
我提出是要像这样一个Android应用程序: 当用户键入一个包含例如“findmyphone”或类似的东西(它不会响应其他正常文本消息)的短信给运行该应用程序的电话,应用程序将自动响应该号码的纬度,经度和地址正在运行应用程序的电话。
我还需要一个按钮来测试它。一旦用户按下“测试”按钮,纬度,经度和地址将出现在2个文本框中,纬度和经度为1,地址在另一个文本框中。非常感谢!这是我到目前为止有:
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;
}
}
}
“我怎样才能做到这一点尽可能简单?”你应该付钱给你这样做...这是最简单的解决方案... – Selvin 2011-12-31 14:51:25
你的错误或问题是什么?任何人都可以复制和粘贴烟幕的代码。 – Robert 2011-12-31 15:52:59
我所需要的一切就是一旦收到短信,以及如何获得经纬度和地址,就会发生一些事情。所以,如果我失去了我的手机,然后我借给他人的电话,并发送短信到该手机,其中包含:“PhoneLocate”,它响应该手机的地址和坐标。但是,只有当这个词是PhoneLocate或者我指定的那个。我已经在android市场上有了一个应用程序,但是它是由应用程序发明者制作的,我想在eclipse中制作,但是在位置上没有太多经验。应用程序名称是:PhoneLocator。 – MySoftware 2011-12-31 16:17:32