場所を継続的に検索し、住所とともに緯度と経度の値を表示する Android プログラムがあります。ルートをマークして、これらの値をマップに表示する必要があります。どうやってするの。
以下は、緯度と経度の値を見つけるためのコードです。
protected void showCurrentLocation()
{
Location location = locationManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER);
if (location != null)
{
// double dd = location.getAltitude();
String message = String.format( "Current Location \n Longitude: %1$s \n Latitude: %2$s ",location.getLongitude(), location.getLatitude() );
Toast.makeText(MainActivity.this, message,Toast.LENGTH_LONG).show();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://IP/YourPhpScript1.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("message", message));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}
これは Address を検索しています:
try
{
Geocoder geocoder = new Geocoder(MainActivity.this, Locale.ENGLISH);
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
String add = strReturnedAddress.toString();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("message", add));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}
myAddress.setText(strReturnedAddress.toString());
}
else
{
myAddress.setText("No Address returned!");
}
私のプログラムは継続的に位置情報を見つけてサーバーに送信します。サーバーからこれらの位置情報を取得し、それらを使用してルートをマークするためのアプリを作成する必要があります。