在android中标记地图上的位置

时间:2012-11-27 04:58:45

标签: android android-mapview android-maps

我有一个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!");
          }

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

0 个答案:

没有答案