1

我有一个 android 程序,它将连续查找位置并显示带有地址的纬度和经度值。我需要通过标记路线在地图中显示这些值。怎么做。

以下是查找 lat 和 lon 值的代码。

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);

     }

这是寻找地址:

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!");
          }

我的程序会不断地查找位置信息并将其发送到服务器。我需要编写一个应用程序来从服务器检索这些位置信息并用它们标记路线。

4

0 回答 0