How to trace routes to gmaps with shapes / polygons

4

I'll need to manipulate a map (preferably gmaps) containing the mesoregions of each state. I found a map of mesoregions created from gmaps , but it does not allow me interactions like creating routes, etc.

How to merge the two features into a single map?

    
asked by anonymous 15.02.2016 / 21:43

2 answers

1

If you plan to route routes as a suggestion of a route from one place to another, whether by car, bus or other means of transport, you should not use shapes / polygons, but api directions service, which is already available in your script for referencing google maps. With this api you can pass two positions in latidude and longitude or by passing the place names (in this case, specifying in which language the names are) and it will return a list of LatLng points with the suggested path. You can also pass up to eight intermediate points wherever the path passes. Then with this list you draw a polyline in maps, it's easy. Directions Service

Now if you want to use the shapes and polygons to draw a design over the regions, you will have to recover several border positions and mount the shapes in the same hand. There are some interesting answers to this. here

    
23.02.2016 / 09:30
0

See if this can help you:

//-- Classe responsável em buscar os pontos de rota (Curva a Curva) do Google
private class getRoute extends AsyncTask<Void, Void, Void>
{
    //-- Método de Execução da Task
    @Override
    protected Void doInBackground(Void... parametro)
    {           
        HttpGet http = new HttpGet("https://maps.google.com/maps?output=json&saddr="+_start+"&daddr="+_end);

        HttpClient httpclient = new DefaultHttpClient();

        HttpResponse response = null;
        try
        {
            response = httpclient.execute(http);
        }
        catch(ClientProtocolException e1)
        {
            e1.printStackTrace();
        }
        catch(IOException e1)
        {
            e1.printStackTrace();
        }

        HttpEntity entity = response.getEntity();

        if(response.getStatusLine().getStatusCode() == 200)
        {
            if(entity != null)
            {
                InputStream instream = null;
                try
                {
                    instream = entity.getContent();
                }
                catch(IllegalStateException e)
                {
                    e.printStackTrace();
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
                String resultString = converterStreamEmString(instream);
                try
                {
                    instream.close();
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }

                String regex = "points:\\"([^\\"]*)\\"";
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(resultString);
                if(m.find())
                {
                    obterPontos(m.group(1));
                }
            }
        }
        return null;
    }


    //-- Converte o binario para double
    private void obterPontos(String str)
    {
        _lat = new ArrayList<Double>();
        _lon = new ArrayList<Double>();

        str = str.replace("\\", "\");

        int index = 0, len = str.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do
            {
                b = str.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            }
            while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

           _lat.add(lat*1E-5);

            shift = 0;
            result = 0;
            do
            {
                b = str.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            }
            while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            _lon.add(lng*1E-5);

            // Usando a lat e lng acima, preencha o objeto que representa 
            // um ponto no mapa (varia de acordo com a API de mapas)
            // e adicione a sua coleção de pontos
        }
    }
}

    //-- Converte o Stream recebido do servidor Google para String
    private String converterStreamEmString(InputStream is)
    {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        int a;
        try
        {
            while ((a = is.read()) != -1)
            { 
                buffer.write(a);
            }
            buffer.close();

        return new String(buffer.toByteArray());

        }
        catch (IOException e)
        {
            e.printStackTrace();
            return e.toString();
        }
    }
    
19.02.2016 / 14:34