从android中的图像到php获取位置,有时会出现错误';我找不到位置

从android中的图像到php获取位置,有时会出现错误';我找不到位置,php,android,image,gps,Php,Android,Image,Gps,我用的是 第一种情况:我正在从PC A运行android应用程序到kitkat和棉花糖设备,然后我尝试将图像上传到服务器,并使用PHP获取位置。结果是,当使用kitkat设备和GPS时,我可以得到它,但在棉花糖中没有 第二种情况:我正在从PC B运行android应用程序,到kitkat和棉花糖设备,然后我尝试将图像上传到服务器,并使用PHP获取位置。结果是我用的是kitkat和棉花糖,两者都无法从图像中获取GPS 第三种情况:我正在运行安卓应用程序,从PC B到设备kitkat和棉花糖,然后我

我用的是 第一种情况:我正在从PC A运行android应用程序到kitkat和棉花糖设备,然后我尝试将图像上传到服务器,并使用PHP获取位置。结果是,当使用kitkat设备和GPS时,我可以得到它,但在棉花糖中没有

第二种情况:我正在从PC B运行android应用程序,到kitkat和棉花糖设备,然后我尝试将图像上传到服务器,并使用PHP获取位置。结果是我用的是kitkat和棉花糖,两者都无法从图像中获取GPS

第三种情况:我正在运行安卓应用程序,从PC B到设备kitkat和棉花糖,然后我尝试将图像上传到服务器,并使用PHP获取位置。但现在我把IP改为使用PC A上的IP连接服务器。结果是,当我使用设备kitkat和GPS时,我可以得到它,但使用棉花糖仍然无法得到位置

在代码中,我已经拥有了使用android运行时的权限。没有logcat错误 我怎样才能解决这个问题

这段代码是PHP

<?php
error_reporting(0);
$latitude = 0;
$longitude = 0;

$lokasi = "uploads/";
$file_name      = $_FILES['image']['name'];
$file_ext       = explode('.',$file_name);
$file_ext       = strtolower(end($file_ext));
$file_size      = $_FILES['image']['size'];
$file_tmp       = $_FILES['image']['tmp_name'];

$filename       = basename($_FILES['image']['name']);
$target_path    = $lokasi . basename($_FILES['image']['name']);
echo basename($_FILES['image']['name'])."<BR>";
//get latitude and longitude
$image_file = $file_tmp;
echo "string : ".$image_file;
if(file_exists($image_file)){
    $details = exif_read_data($image_file); 
    $sections = explode(',',$details['SectionsFound']); 

    if(in_array('GPS',array_flip($sections))){ 

        echo $latitude = number_format(format_gps_data($details['GPSLatitude'],$details['GPSLatitudeRef']),10, ',', ' '); 
        $longitude = number_format(format_gps_data($details['GPSLongitude'],$details['GPSLongitudeRef']),10, ',', ' '); 
    }
    else{
        die('GPS data not found'); 
    }
}
else{
    die('File does not exists'); 
}

function format_gps_data($gpsdata,$lat_lon_ref){
    $gps_info = array();
    foreach($gpsdata as $gps){
        list($j , $k) = explode('/', $gps);
        array_push($gps_info,$j/$k);
    }
    $coordination = $gps_info[0] + ($gps_info[1]/60.00) + ($gps_info[2]/3600.00);
    return (($lat_lon_ref == "S" || $lat_lon_ref == "W" ) ? '-'.$coordination : $coordination).' '.$lat_lon_ref;
}
///////////////////////////////

$nama_file = $latitude . "_" . $longitude . "." . $file_ext;
$target_path=$lokasi . $nama_file;


try {
    //throw exception if can't move the file
    if (!move_uploaded_file($file_tmp, $target_path)) {
        throw new Exception('Could not move file');
    }

    echo "Success";
} catch (Exception $e) {
    die('File did not upload: ' . $e->getMessage());
}
?>

你在这里丢的代码太多了。您只能发布相关代码。只有上传代码可以。为什么要用相机、权限和数据库来打扰我们?请删除所有这些内容。@greenapps,因为首先应用程序“打开摄影机”,但“打开摄影机”必须具有权限,然后图像才能上载。我们都知道这一点。这与你的问题无关。那么请启动垃圾收集器,像这样的应用程序?我认为php代码将非常有用。。我怎样才能解决我的问题?好的。这是一个开始。但是为什么要用onCreate完成一个完整的活动呢?那个数据库插入?一切都无关紧要。请全部放下。只有上传异步任务才能完成。你应该发布一个最小的例子。Php确实很有用。如果你是c!快点,我们就可以开始帮你了。
    private class UploadFileToServer extends AsyncTask<Void, Integer, String> {
        @Override
        protected void onPreExecute() {
            // setting progress bar to zero
            progressBar.setProgress(0);
            super.onPreExecute();
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {
            // Making progress bar visible
            progressBar.setVisibility(View.VISIBLE);

            // updating progress bar value
            progressBar.setProgress(progress[0]);

            // updating percentage value
            txtPercentage.setText(String.valueOf(progress[0]) + "%");
        }

        @Override
        protected String doInBackground(Void... params) {
            return uploadFile();
        }

        @SuppressWarnings("deprecation")
        private String uploadFile() {
            String responseString = null;

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);

            try {
                AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                        new ProgressListener() {

                            @Override
                            public void transferred(long num) {
                                publishProgress((int) ((num / (float) totalSize) * 100));
                            }
                        });

                File sourceFile = new File(filePath);

                // Adding file data to http body
                entity.addPart("image", new FileBody(sourceFile));
                image = new FileBody(sourceFile);
                // Extra parameters if you want to pass to server
                entity.addPart("website",
                        new StringBody("www.androidhive.info"));
                entity.addPart("email", new StringBody("abc@gmail.com"));

                totalSize = entity.getContentLength();
                httppost.setEntity(entity);

                // Making server call
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity r_entity = response.getEntity();

                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    // Server response
                    responseString = EntityUtils.toString(r_entity);
                } else {
                    responseString = "Error occurred! Http Status Code: "
                            + statusCode;
                }

            } catch (ClientProtocolException e) {
                responseString = e.toString();
            } catch (IOException e) {
                responseString = e.toString();
            }

            return responseString;

        }

        @Override
        protected void onPostExecute(String result) {
            Log.e(TAG, "Response from server: " + result);

            // showing the server response in an alert dialog
            showAlert(result);

            super.onPostExecute(result);
        }

    }