Android 我想将经度和纬度(手机的当前位置)发送到JSP页面,并将其存储到MYSQL数据库中
我想创建android应用程序,将手机的当前位置发送到JSP页面,然后将其存储到MySQL中。通过使用以下代码,我得到了位置,但如何将经度和纬度发送到JSP页面 这是代码Android 我想将经度和纬度(手机的当前位置)发送到JSP页面,并将其存储到MYSQL数据库中,android,Android,我想创建android应用程序,将手机的当前位置发送到JSP页面,然后将其存储到MySQL中。通过使用以下代码,我得到了位置,但如何将经度和纬度发送到JSP页面 这是代码 public class GPSMyListView extends Activity { int increment = 4; MyLocation myLocation = new MyLocation(); double Longitude,Latitude; @Override protected void onC
public class GPSMyListView extends Activity {
int increment = 4;
MyLocation myLocation = new MyLocation();
double Longitude,Latitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gpsmy_list_view);
myLocation.getLocation(getApplicationContext(), locationResult);
boolean r = myLocation.getLocation(getApplicationContext(),locationResult);
TextView Longi =(TextView)findViewById(R.id.Longitude);
TextView Lati =(TextView)findViewById(R.id.Latitude);
DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
String formattedValue = decimalFormat.format(Longitude);
Longi.setText(formattedValue);
Lati.setText(formattedValue);
}
public LocationResult locationResult = new LocationResult() {
@Override
public void gotLocation(Location location) {
// TODO Auto-generated method stub
Longitude= location.getLongitude();
Latitude= location.getLatitude();
// updateDatabase();
Toast.makeText(getApplicationContext(), "THis is u r phone Location",Toast.LENGTH_LONG).show();
System.out.println("**************************************************");
System.out.println(+Longitude);
System.out.println("**************************************************");
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gpsmy_list_view, menu);
return true;
}
}
这里是我用来发送经度和纬度到我的jsp页面。。。。。但它不起作用
字符串l1=String.valueOf(languites);
字符串l2=String.valueOf(纬度):
HttpClient=new DefaultHttpClient()
HttpPost-HttpPost=新的HttpPost(“http://127.0.0.1:8084/TrackPhone/login1.jsp");
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“经度”,经度));
添加(新的BasicNameValuePair(“纬度”,纬度));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
请使用HttpGet
而不是使用HttpPost
,并在查询字符串中传递参数,如下所示:
String url = "http://127.0.0.1:8084/TrackPhone/login1.jsp?Longitude="+Longitude+"&Latitude="+Latitude;
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
// add request header
//request.addHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(request);
System.out.println("Response Code : " +response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null)
{
result.append(line);
}
在jsp
中,获取如下参数:
Longitude: <%= request.getParameter("Longitude") %>
Latitude: <%= request.getParameter("Latitude") %>
经度:
纬度:
您将如何在应用程序中访问jsp页面,即您是否使用webview显示该页面?感谢您的关注。。。。。。我已经在NetBeans中创建了一个JSP站点。。并在本地主机上运行它。现在我想把我的经度和纬度(我用上面的代码得到的)发送到我的这个JSP页面…添加了答案,请检查一下。
Longitude: <%= request.getParameter("Longitude") %>
Latitude: <%= request.getParameter("Latitude") %>