Cuizhiyong / vopenlayers

Automatically exported from code.google.com/p/vopenlayers
0 stars 0 forks source link

GeoCoding using openrouteservice #74

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Please add a geocoding feature

function submitform() {
            var queryString = document.forms[0].query.value;
            OpenLayers.Request.POST({
                url: "http://www.openrouteservice.org/php/OpenLSLUS_Geocode.php",
                scope: this,
                failure: this.requestFailure,
                success: this.requestSuccess,
                headers: {"Content-Type": "application/x-www-form-urlencoded"},
                data: "FreeFormAdress=" + encodeURIComponent(queryString) + "&MaxResponse=1"
            });
        }
        function requestSuccess(response) {
            var format = new OpenLayers.Format.XLS();
            var output = format.read(response.responseXML);
            if (output.responseLists[0]) {
                var geometry = output.responseLists[0].features[0].geometry;
                var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
                        new OpenLayers.Projection("EPSG:4326"),
                        map.getProjectionObject()
                        );
                map.setCenter(foundPosition, 16);
            } else {
                alert("Sorry, no address found");
            }
        }
        function requestFailure(response) {
            alert("An error occurred ");
        }

//eof

Original issue reported on code.google.com by mauretto79@gmail.com on 23 May 2012 at 10:00

GoogleCodeExporter commented 8 years ago
Hi,

Do you think there should be some sort of special API's? I think it should be 
quite easy to use that kind of services already on the serverside. First use 
URL.openStream and pipe that the XML parser and then handle that.

cheers,
matti

Original comment by matti.ta...@gmail.com on 27 Jul 2012 at 11:37

GoogleCodeExporter commented 8 years ago
Here is one example of what I meant, but using Google service:
http://code.google.com/p/gmaps-samples/source/browse/trunk/geocoder/java/Geocodi
ngSample.java?r=2476

Original comment by matti.ta...@gmail.com on 27 Jul 2012 at 1:17