2012-12-13 6 views
0

NETWORK PROVIDER를 사용하여 위도와 경도 값을 찾아서 고정 IP를 사용하여 SERVER에 저장합니다 (위도와 경도 값). MYSQL DATABASE 에서처럼. 괜찮습니다.MySQL 데이터베이스에 저장된 값을 사용하여 Google지도를 표시합니다.

이제 MYSQL 데이터베이스에서 위도와 경도 값을 검색하고 Android지도에서 Google지도에 표시하는 클라이언트 응용 프로그램을 작성해야합니다. 그것을하는 방법. 나는 지난 4 일 동안 이것에 맞았다. 솔루션

을 찾아 도와주세요 내 코드는 다음

public class MainActivity extends Activity { 

Location location; 
protected LocationManager locationManager; 
private LocationListener ll ; 
private TextView tv ; 
EditText msgTextField; 
int delay = 1000; 
int period=10000; 


/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 

    boolean gpsEnabled = true; 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    // AlarmManager manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE); 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    tv= new TextView (this); 
    try { 
    gpsEnabled =locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
    // Toast.makeText(MainActivity.this,"ggg ",Toast.LENGTH_LONG).show(); 
    } 
    catch (Exception e) 
    { 

    } 
    locationManager. requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 5, new MyLocationListener()); 
    Log.d("gps","Gps supports altitude"+ locationManager.getProvider(LocationManager.NETWORK_PROVIDER).supportsAltitude()); 
    List<String> providers=locationManager.getAllProviders(); 
    for(String provider : providers) 
    { 
     Toast.makeText(MainActivity.this,provider,Toast.LENGTH_LONG).show(); 
    } 
    for(int w=0;w <providers.size();w++) 
    { 
    Log.d("Location Test ","provider "+w +":"+providers.get(w)); 

    } 
    providers =locationManager.getProviders(true); 

    final Button send = (Button) this.findViewById(R.id.sendButton); 

    send.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 

      showCurrentLocation(); 


     } 
    }); 

    Button send1 = (Button) this.findViewById(R.id.sendButton1); 

    send1.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 

      Intent viewIntent =new Intent(MainActivity.this,Mapview.class); 
      startActivity(viewIntent); 

     } 
    }); 


    Button start=(Button) this.findViewById(R.id.startSercice1); 


start.setOnClickListener(new View.OnClickListener() { 

    public void onClick(View arg0) { 
     startService(new Intent(MainActivity.this,SimpleService.class));  

    } 
}); 
    Button stop=(Button) this.findViewById(R.id.stopService1); 
    stop.setOnClickListener(new View.OnClickListener() { 

public void onClick(View v) { 
    stopService(new Intent(MainActivity.this,SimpleService.class)); 

} 
}); 
} 

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://xx.xx.xx.xx/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); 

    } 
catch (ClientProtocolException e) 
    { 

    } 
catch (IOException e) 
    { 

    } 


    } 

    } 

    private class MyLocationListener implements LocationListener 
    { 

    public void onLocationChanged(final Location location) 
    { 

     final String message = String.format("New 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://xx.xx.xx.xx/YourPhpScript1.php"); 
     double LONGITUDE = location.getLongitude(); 
     double LATITUDE = location.getLatitude(); 
     TextView myAddress = (TextView)findViewById(R.id.myaddress); 

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



     } 
    catch (IOException e) 
    { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      myAddress.setText("Canont get Address!"); 
    } 

    // double ddd =location.getAltitude(); 


// pendingIntent =PendingIntent.getService(MainActivity.this,1,intent,1); 
     final String message1 = String.format("New Location \n Longitude: %1$s \n Latitude: %2$s ",location.getLongitude(), location.getLatitude()); 
     Toast.makeText(MainActivity.this, message1, Toast.LENGTH_LONG).show(); 

    new Timer().schedule(new TimerTask() 
    { 

    public void run() 
    { 

    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost("http://xx.xx.xx.xx/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)); 

    //manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+200000, pendingIntent); 
     httpclient.execute(httppost); 

    } 

catch (ClientProtocolException e) 
    { 

    } 
catch (IOException e) 
    { 

    } 

    } 
    },60000); 



    } 

    public void onStatusChanged(String s, int i, Bundle b) 
    { 
    Toast.makeText(MainActivity.this, "Provider status changed",Toast.LENGTH_LONG).show(); 
    } 
    public void onProviderDisabled(String s) 
    { 
    Toast.makeText(MainActivity.this,"Provider disabled by the user. GPS turned off",Toast.LENGTH_LONG).show(); 

    } 

    public void onProviderEnabled(String s) 
    { 
    Toast.makeText(MainActivity.this,"Provider enabled by the user",Toast.LENGTH_LONG).show(); 
    } 

    } 




} 
+0

당신은 몇 가지 코드를 보여 주시겠습니까? 네가하지 않으면 너를 도울 수 없어 – DrinkJavaCodeJava

+0

@ redelman431 내 질문보기. 내가 편집했습니다 – user1844654

답변

0

당신은지도를 보여 그 후, 당신은 웹보기를 사용할 수 AsyncTask를을 사용하여 데이터베이스의 위도와 경도를 얻을해야하고, 채점자.

https://developers.google.com/maps/articles/android_v3

+0

안드로이드 응용 프로그램 안의 데이터베이스에서 값을 가져 오는 데 문제가 있습니다. 어떻게하는지 – user1844654

관련 문제