1

I have an android program which will find location continuously and display the latitude and longitude values with address. I need to show these values in map by marking a route. How to do it.

Following is the code for finding lat and lon values.

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

     }

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

My program will continuously find location information and sends it to server. I need to write an app for retrieving those location info from server and marking route with those.

user1844654
  • 133
  • 1
  • 2
  • 14

0 Answers0