将多边形值传递给php

时间:2014-06-20 05:39:13

标签: php android json postgresql polygon

从我的android程序中我使用了Openstreetmap,然后使用它在overlay上绘制多边形。我在数组中保存了x坐标和y坐标。现在我需要在我的数据库中传递这个坐标(POstgresql)我已在我的数据库中定义了一个多边形类型数据。为此,我尝试了这些代码。

    Overlay touchOverlay = new Overlay(this){
        ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null; 
        @Override
        protected void draw(Canvas arg0, MapView arg1, boolean arg2) {

        }
        @Override
        public boolean onSingleTapConfirmed(final MotionEvent e, final MapView      mapView) {
                mapview.invalidate();
            proj = mapView.getProjection();
            loc = (GeoPoint) proj.fromPixels((int)e.getX(), (int)e.getY());

            longitude = Double.toString(((double)loc.getLongitudeE6())/1000000);
            latitude = Double.toString(((double)loc.getLatitudeE6())/1000000);

            myPath.addPoint(loc);
            mPoints.add(new Point(loc.getLatitudeE6(),loc.getLongitudeE6()));
            xcor.add(((double)loc.getLongitudeE6())/1000000);
            ycor.add(((double)loc.getLatitudeE6())/1000000);

            return true;
        }
    }  

我使用Asynctask来调用php

    private void postData() {
            InputStream isr = null;
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://192.168.5.1/project/spatial.php");
            try {

                JSONArray listx = new JSONArray();
                JSONArray listy = new JSONArray();
                for (int i = 0; i < xcor.size(); i++) {
                    listx.put(xcor.get(i));                             
                    listy.put(ycor.get(i));                             
                }
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("value1", listx.toString()));
                params.add(new BasicNameValuePair("value2", listy.toString()));
                httppost.setEntity(new UrlEncodedFormEntity(params));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                isr = entity.getContent();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso-8859-1"),8);
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                            sb.append(line + "\n");
                    }
                    isr.close();
                    String result=sb.toString();



                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

如何使用此坐标以数据库????

中的多边形数据类型发布

0 个答案:

没有答案