用户如何突出显示街道的某个部分并将其上传到自定义地图服务器?

时间:2013-09-26 15:25:14

标签: android google-maps highlight google-maps-api-2 street-address

问题非常简单,但我会给你一些更多的背景信息: 我的团队正在尝试制作一个Android应用程序,用户可以在其中突出显示街道的某个部分,为其添加颜色并将该信息发送到服务器。我已经开始使用谷歌地图API V2,但到目前为止,我唯一得到的是带有缩放按钮的工作地图。 我还阅读了这个帖子possible to highlight a section of a street?,但是没有关于用户如何从应用程序执行此操作的信息。 我想知道,首先,如果这是可能的,第二,怎么可能做到。 谢谢。

2 个答案:

答案 0 :(得分:1)

我做了类似的事情,但是一年多以前它出现在Google Maps V1上。在我的情况下,我只是绘制线条形式的位置点。

这是我旧代码的一部分:

class MapOverlay extends Overlay
{     
    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);           

            if(startPoint != null && stopPoint != null)
            {           
                Point screenPts = new Point();

                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);             
                paint.setStrokeWidth(4);

                if(startCounter >= 0)
                {
                    int len = mapPoints.size();

                    if(route > 0)
                    {
                        route = route - (int)(5*(((((gtpPoints.get(len - route).speed)*3600)/1000))/maxSpeed)+1);               
                    }

                    if(route <= 0)
                    {
                        route = 0;
                    }

                    if(len > 1)
                    {
                        for(int i = 1; i< len - route; i++)
                        {
                            Point startPoint = new Point();
                            Point stopPoint = new Point();

                            mapView.getProjection().toPixels(mapPoints.get(i-1).point, startPoint);
                            mapView.getProjection().toPixels(mapPoints.get(i).point, stopPoint);

                            LinearGradient gradient = new LinearGradient(startPoint.x, startPoint.y, stopPoint.x, stopPoint.y, mapPoints.get(i-1).color, mapPoints.get(i).color, android.graphics.Shader.TileMode.REPEAT);
                            paint.setShader(gradient);

                            paint.setColor(mapPoints.get(i).color);
                            canvas.drawPoint(stopPoint.x, stopPoint.y, paint);

                            canvas.drawLine(startPoint.x, startPoint.y, stopPoint.x, stopPoint.y, paint);
                        }
                    }
                }

                if(startCounter > 0)
                {
                    startCounter = startCounter - 1;
                }



                if(onePoint == false)
                {
                    mapView.getProjection().toPixels(startPoint, screenPts);

                    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.start_point);
                    canvas.drawBitmap(bmp, screenPts.x-bmp.getWidth()/2, screenPts.y-bmp.getHeight()/2, null);     

                    mapView.getProjection().toPixels(stopPoint, screenPts);

                    Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.stop_point);
                    canvas.drawBitmap(bmp2, screenPts.x-bmp2.getWidth()/2, screenPts.y-bmp2.getHeight()/2, null);     
                }
                else
                {
                    mapView.getProjection().toPixels(startPoint, screenPts);

                    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pointer);
                    canvas.drawBitmap(bmp, screenPts.x-bmp.getWidth()/2, screenPts.y-bmp.getHeight()/2, null);     
                }
            }


        return true;
    }
} 

答案 1 :(得分:0)

我想出了如何做到这一点,但这对我的位置非常具体,哥伦比亚。 由于哥伦比亚街道地址格式化 “Carrera(号码)#(号码) - (号码)”或“Calle(号码)#(号码) - (号码)”

并且Geocoder像这样处理哥伦比亚的地址 “Carrera(number1)#(number2) - (number3)a#(number2) - (number4)” 其中number3是街道的起点,number4是街道的尽头,我所做的是一系列分裂:

    private Polyline crearPolyline(List<Address> a2, GoogleMap map) {

            Address ad = a2.get(0);
            String address = ad.getAddressLine(0);
            System.out.println(address);
                //Gets "number3 a #number2-number4"
            String[] addressSplit = address.split("-");
            String addressA = null, addressB = null;
            Polyline p = null;
            try {

                //Gets number3 and "a " number4
                String[] addressSplit2 = addressSplit[1].split(" a ");

                //Start address for the polyline
                addressA=addressSplit[0]+"-"+addressSplit2[0]+", Bogotá";
                LatLng a = getLatLongFromAddress(addressA);
                            //End address for the polyline
                addressB=addressSplit[0]+"-"+addressSplit[2]+", Bogotá";
                LatLng b = getLatLongFromAddress(addressB);


                System.out.println(addressA);
                System.out.println(addressB);
                p = map.addPolyline(new PolylineOptions().add(a,b).color(Color.BLUE));

            } catch (Exception e) {

                Toast.makeText(getApplicationContext(), "Procure tocar calles rectas", Toast.LENGTH_LONG).show(); 
//If the polyline can't be painted, the street might not be straight.
            }

            return p;
        }

我希望这对没有去过哥伦比亚的人有意义。