单击图像时如何存储位置?

时间:2015-02-17 04:51:03

标签: android camera gps

我正在开发一个应用程序,我需要从Android摄像头拍摄一些照片,我需要存储图像和该图像的位置,通过Web服务在服务器中单击它。所以请帮我成功完成这项任务。

1 个答案:

答案 0 :(得分:1)

制作照片的代码:

public class MyCameraActivity extends Activity {
    private static final int CAMERA_REQUEST = 1888; 
    private ImageView imageView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);
        Button photoButton = (Button) this.findViewById(R.id.button1);
        photoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent, CAMERA_REQUEST); 
            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            imageView.setImageBitmap(photo);
        }  
    } 
}

这是source

至于获取gps坐标,您应该使用LocationListener

public class MyCurrentLoctionListener implements LocationListener {

public String myLocation;
private TextView mTextView;

MyCurrentLoctionListener(TextView tv) {
    this.mTextView = tv;    
}

@Override
public void onLocationChanged(Location location) {
    location.getLatitude();
    location.getLongitude();

    mTextView.setText("Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude());

}

这是source

对于服务器上的传输数据,我建议您使用Retrofit进行REST API。如果没有REST API,请使用您提供的服务API。