将多边形值传递给php
在我的android程序中,我使用了Openstreetmap,然后使用它在上面使用overlay绘制多边形。我在数组中保存了x坐标和y坐标。现在我需要在我的数据库(POstgresql)中传递这些坐标。我在数据库中定义了多边形类型的数据。为此,我尝试了以下代码将多边形值传递给php,php,android,json,postgresql,polygon,Php,Android,Json,Postgresql,Polygon,在我的android程序中,我使用了Openstreetmap,然后使用它在上面使用overlay绘制多边形。我在数组中保存了x坐标和y坐标。现在我需要在我的数据库(POstgresql)中传递这些坐标。我在数据库中定义了多边形类型的数据。为此,我尝试了以下代码 Overlay touchOverlay = new Overlay(this){ ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverla
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;
}
}
Overlay touchOverlay=新覆盖(此){
itemizedictionoverlay另一个itemizedictionoverlay=null;
@凌驾
受保护的空绘图(画布arg0、地图视图arg1、布尔值arg2){
}
@凌驾
公共布尔值OnSingleTapConfiged(最终运动事件e,最终地图视图地图视图){
mapview.invalidate();
proj=mapView.getProjection();
loc=(地理点)proj.fromPixels((int)e.getX(),(int)e.getY());
经度=Double.toString(((Double)loc.getLongitudeE6())/1000000);
纬度=Double.toString(((Double)loc.getLatitudeE6())/1000000);
myPath.addPoint(loc);
添加(新点(loc.getLatitudeE6(),loc.getLongitudeE6());
xcor.add(((双)loc.getLongitudeE6())/1000000);
ycor.add(((双)loc.getLatitudeE6())/1000000);
返回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();
}
}
private void postData(){
InputStream isr=null;
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://192.168.5.1/project/spatial.php");
试一试{
JSONArray listx=新的JSONArray();
JSONArray listy=新的JSONArray();
对于(int i=0;i
如何使用此坐标在数据库中的多边形数据类型中发布???您使用什么客户端与PostgreSQL通信?--您可以始终使用多边形的字符串输入表示法:谢谢。这对我很有用