显示经纬度的网络服务器 [英] Display Latitude and longitude on a webserver

查看:117
本文介绍了显示经纬度的网络服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图显示,因为几天协调到Web服务器上的GPS,但还没有得出任何定论。
我所试图做的是让纬度和一个人的经度,然后在Web服务器上显示出来。我有一个PHP服务器和MySQL数据库。 没有错误,但没有对URL显示任何内容

 公共类UseGps扩展活动{
/ **当第一次创建活动调用。 * /@覆盖公共无效的onCreate(捆绑savedInstanceState){super.onCreate(savedInstanceState);的setContentView(R.layout.main);/ *使用的LocationManager类获取GPS位置* /的LocationManager mlocManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);LocationListener的mlocListener =新MyLocationListener();mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mlocListener);}/ *类我的位置监听器* /公共类MyLocationListener实现LocationListener的{
 上下文语境;
 公共无效onLocationChanged(位置LOC){
双纬度= loc.getLatitude();双经度= loc.getLongitude();
Toast.makeText(上下文中,纬度:+纬度+经度:+经度,5000).show();
TelephonyManager telephonyManager =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
串DEVID = telephonyManager.getDeviceId();
//这是JSON部分把你的信息里面
字符串POSTDATA = \"{\\\"request\\\":{\\\"type\\\":\\\"locationinfo\\\"},\\\"userinfo\\\":{\\\"Devid\\\":\\\"\"+Devid+\"\\\",\\\"latitude\\\":\\\"\"+latitude+\"\\\",\\\"longitude\\\":\\\"\"+longitude+\"\\\"}}\";URI URI = Uri.parse(http://location.site88.net/store.php);
意向意图=新意图(Intent.ACTION_VIEW,URI);
startActivity(意向);
字符串URL =htt​​p://location.site88.net/storeg.php;DefaultHttpClient的HttpClient =新DefaultHttpClient();
HttpPost httpPost =新HttpPost(URL);清单<&的NameValuePair GT; namevaluepairs中=新的ArrayList<&的NameValuePair GT;(3);
nameValuePairs.add(新BasicNameValuePair(DEVID,DEVID));
nameValuePairs.add(新BasicNameValuePair(纬度,Double.toString(纬度)));
nameValuePairs.add(新BasicNameValuePair(经度,Double.toString(经度)));尝试{
    httpPost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));
}赶上(UnsupportedEncodingException E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}
HTT presponse HTT presponse = NULL;
字符串结果= NULL;
尝试{
    HTT presponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = HTT presponse.getEntity();
    如果(httpEntity!= NULL){
        InputStream的河道= NULL;
        河道= httpEntity.getContent();
        读者的BufferedReader =新的BufferedReader(新的InputStreamReader(插播广告,ISO-8859-1),8);
        StringBuilder的SB =新的StringBuilder();
        串线= NULL;
        而((行= reader.readLine())!= NULL){
            sb.append(行+\\ n);
            Toast.makeText(getApplicationContext(),通,Toast.LENGTH_SHORT).show();
        }
         instream.close();
              结果= sb.toString();
      }
}赶上(ClientProtocolException E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}赶上(IOException异常E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}
}
公共无效onProviderDisabled(字符串提供商){
// TODO自动生成方法存根}
公共无效onProviderEnabled(字符串提供商){
// TODO自动生成方法存根}
公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
// TODO自动生成方法存根  }}}


解决方案

使用

  nameValuePairs.add(新BasicNameValuePair(纬度,Double.toString(纬度)));
nameValuePairs.add(新BasicNameValuePair(经度,Double.toString(经度)));
nameValuePairs.add(新BasicNameValuePair(DEVID,DEVID));
尝试{
    httpPost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));
}赶上(UnsupportedEncodingException E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}
HTT presponse HTT presponse = NULL;
尝试{
    HTT presponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = HTT presponse.getEntity();
    如果(httpEntity!= NULL){
        InputStream的河道= NULL;
        河道= httpEntity.getContent();
        读者的BufferedReader =新的BufferedReader(新的InputStreamReader(插播广告,ISO-8859-1),8);
        StringBuilder的SB =新的StringBuilder();
        串线= NULL;
        而((行= reader.readLine())!= NULL){
            sb.append(行+\\ n);
            Toast.makeText(getApplicationContext(),通,Toast.LENGTH_SHORT).show();
        }
         instream.close();
              结果= sb.toString();
      }
}赶上(ClientProtocolException E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}赶上(IOException异常E1){
    // TODO自动生成catch块
    e1.printStackTrace();
}

而不是

 的Htt presponse响应= httpClient.execute(httpPost);
InputStream的httpEntity = HTT presponse.getEntity()的getContent()。

I have been trying to display the gps coordinated to a web server since several days but havent come to any conclusion yet. What i am trying to do is to get the latitudes and longitudes of a person and then display them on the webserver. I got a php server and mysql database. There is no error but There is nothing displayed on the url

public class UseGps extends Activity 

{ 


/** Called when the activity is first created. */ 

@Override 

public void onCreate(Bundle savedInstanceState) 

{ 

super.onCreate(savedInstanceState); 

setContentView(R.layout.main); 



/* Use the LocationManager class to obtain GPS locations */ 

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

LocationListener mlocListener = new MyLocationListener(); 



mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 



} 



/* Class My Location Listener */ 

public class MyLocationListener implements LocationListener 

{ 
 Context context;
 public void onLocationChanged(Location loc) 

{ 


double latitude = loc.getLatitude(); 

double longitude = loc.getLongitude(); 
Toast.makeText(context, "Latitude:" +latitude + "Longitude:" +longitude, 5000).show();
TelephonyManager telephonyManager =    (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String Devid = telephonyManager.getDeviceId();




//this is JSON part to put your information inside it
String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"Devid\":\""+Devid+"\",\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\"}}";

Uri uri = Uri.parse("http://location.site88.net/store.php"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 
String url="http://location.site88.net/storeg.php"; 

DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(url); 

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("Devid", Devid));
nameValuePairs.add(new BasicNameValuePair("latitude", Double.toString(latitude) )); 
nameValuePairs.add(new BasicNameValuePair("longitude", Double.toString(longitude))); 

try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
HttpResponse httpResponse = null;
String result = null;
try {
    httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        InputStream instream = null;
        instream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream,"iso-8859-1"),8); 
        StringBuilder sb = new StringBuilder(); 
        String line = null; 
        while ((line = reader.readLine()) != null) { 
            sb.append(line + "\n"); 
            Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
        } 
         instream.close();
              result=sb.toString(); 
      }
} catch (ClientProtocolException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

  }}}

解决方案

use

nameValuePairs.add(new BasicNameValuePair("latitude", Double.toString(latitude) )); 
nameValuePairs.add(new BasicNameValuePair("longitude", Double.toString(longitude))); 
nameValuePairs.add(new BasicNameValuePair("devid", devid)); 
try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
HttpResponse httpResponse = null;
try {
    httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        InputStream instream = null;
        instream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream,"iso-8859-1"),8); 
        StringBuilder sb = new StringBuilder(); 
        String line = null; 
        while ((line = reader.readLine()) != null) { 
            sb.append(line + "\n"); 
            Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
        } 
         instream.close();
              result=sb.toString(); 
      }
} catch (ClientProtocolException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 

instead of

HttpResponse Response = httpClient.execute(httpPost); 
InputStream httpEntity = httpResponse.getEntity().getContent(); 

这篇关于显示经纬度的网络服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆