--
You could use the Esri provider,and pass in the country as option.
Just like:
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Esri({country: 'Portugal'})
}).addTo(map);
Thats possible with the OpenStreetMap provider also, but there you need to provide a 'countryCode'. I guess Portugal has code 'PT'?
And I'm not quite sure, but I think that thats where the google sensor parameter is for. I'll look at that for you tomorrow.
If that's the case, then this should work:
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Google({sensor: true})
}).addTo(map);
Again, not sure about the last one. Esri and OSM should devenitely work.
--
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Google({
region: 'pt'
})
}).addTo(map);
--
--
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Google({
language: 'en',
region: 'nl'
})
}).addTo(map);
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Bing({
key: '__YOUR_BING_API_KEY_HERE__'
})
}).addTo(map);
GeocoderResults
object seems to return a lot more data . I understand it would be hard work to develop a common interface that supports all features of each provider. I just wonder whether we would eventually need this data in the future, particularly those properties within the geometry object.results[]: {
types[]: string,
formatted_address: string,
address_components[]: {
short_name: string,
long_name: string,
types[]: string
},
geometry: {
location: LatLng,
location_type: GeocoderLocationType
viewport: LatLngBounds,
bounds: LatLngBounds
}
}
Hi again Stefan,
geosearch: function (qry) {
try {
var provider = this._config.provider;
var url = provider.GetServiceUrl(qry);
$.getJSON(url, function (data) {
try {
var results = provider.ParseJSON(data);
if (results.length == 0)
throw this._config.notFoundMessage;
this._showLocation(results[0].X, results[0].Y, results[0].Label);
}
catch (error) {
}
}.bind(this));
}
catch (error) {
}
}
$('#leaflet-control-geosearch-qry').parent().append('<span>boooooooo</span>');@Leaflet Newbie
$('#leaflet-control-geosearch-qry').parent().prepend('<img src="./search-icon.png" />');
geosearch: function (qry) {
var provider = this._config.provider;
var url = provider.GetServiceUrl(qry);
if (!($.browser.msie && window.XDomainRequest)) {
try {
$.getJSON(url, function (data) {
try {
this._handleSuccess(data);
}
catch (error) {
this._printError(error);
}
}.bind(this));
}
catch (error) {
this._printError(error);
}
} else {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", url);
xdr.onload = function () {
try {
var data = jQuery.parseJSON(xdr.responseText); // we must parse response from XDR object
this._handleSuccess(data);
} catch (error) {
this._printError(error);
}
}.bind(this);
xdr.onerror = function () {
this._printError(xdr.responseText);
}.bind(this);
xdr.send();
}
},
_handleSuccess: function (data) {
var results = this._config.provider.ParseJSON(data);
if (results.length == 0)
throw this._config.notFoundMessage;
this._showLocation(results[0].X, results[0].Y, results[0].Label);
},
--
map.on('geosearch_foundlocations', function(results) { for(var i = 0; i < results.Locations.length; i++) console.log(results.Locations[i].Label); });
The second event is called as soon as the map starts to move to the found location. It returns the the same data as the 'foundlocations' event, but this time only a single record is returned instead of an array.
map.on('geosearch_showlocation', function(result) { console.log('zoom to: '+result.Location.Label); });You can hook your call in like:
map.on('geosearch_showlocation', function(result) { $.ajax({ type: 'POST', url: 'http://yourdomain.com/endpoint', data: { x: result.Location.X, y: result.Location.Y } }).done(function(response) { //data submitted }); });
Hope this helps you out.
--
var rootUrl = 'http://geoserver.capecodgis.com/geoserver/capecodgis/ows' var defaultParameters = { service: 'WFS', version: '1.0.0', request: 'GetFeature', typeName: 'capecodgis:blockgroups_2010_4326', maxFeatures: 100, outputFormat: 'json', format_options: 'callback:getJson' }; var customParams = { bbox: map.getBounds().toBBoxString(), cql_filter: 'CONTAINS(the_geom, POINT('+thisLatLon+'))' }; var parameters = L.Util.extend(defaultParameters, customParams); console.log(rootUrl + L.Util.getParamString(parameters));
Again, thanks for your help, I got quite a bit done with my new found knowledge.
<HTML><HEAD><TITLE> First WebGIS </TITLE><link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" /><link rel="stylesheet" type="text/css" href="style.css" /><!--[if lte IE 8]><link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /><![endif]--><script src="src/js/l.control.geosearch.js"></script><script src="src/js/l.geosearch.provider.google.js"></script><link rel="stylesheet" type="text/css" href="src/css/l.geosearch.css"></HEAD><BODY><P> </P><div id="map"></div><script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script><script>window.onload = function () {function getURLParameter(name) {return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,])[1]);}var regionParameter = getURLParameter('region');var region = (regionParameter === 'undefined') ? '' : regionParameter;var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/{z}/{x}/{y}.png', cloudmadeAttribution ='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>', cloudmade = new L.tileLayer(cloudmadeUrl, {maxZoom :18,attribution: cloudmadeAttribution ,});var roads = new L.TileLayer.WMS("http://localhost:8082/geoserver/wms",{layers:'sf:roads',format:'image/png',transparent:true});var water = new L.TileLayer.WMS("http://localhost:8082/geoserver/wms",{layers:'topp:tasmania_water_bodies',format:'image/png',transparent:true});var map = new L.map('map', {center: [30.0,0.0],zoom:2,layers: [cloudmade, roads, water],zoomControl:true});new L.Control.GeoSearch({provider: new L.GeoSearch.Provider.Google({region: region})}).addTo(map);};</script></BODY></HTML>
<script src="leaflet.js"></script>
I was able to install it looking at the demo! Unfortunately now I get the search bar but if I search something nothing happens!Do you know where is my mistake? The code is the following:<html><head><title> Locate </title><link rel="stylesheet" href="leaflet.css">
<!--[if lte IE 8]><link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /><![endif]-->
<link rel="stylesheet" href="l.geosearch.css"><script src="http://code.jquery.com/jquery-1.8.3.min.js"></script><script src="l.control.geosearch.js"></script><script src="l.geosearch.provider.google.js"></script><link rel="stylesheet" href="l.geosearch.css"></head><body><p> </p><div id="map" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" class="leaflet-container leaflet-fade-anim" tabindex="0"><div class="leaflet-map-pane" style="-webkit-transform: translate3d(0px, 0px, 0);"><div class="leaflet-tile-pane"><div class="leaflet-layer"></div></div><div class="leaflet-objects-pane"><div class="leaflet-shadow-pane"></div><div class="leaflet-overlay-pane"></div><div class="leaflet-marker-pane"></div><div class="leaflet-popup-pane"></div></div></div><div class="leaflet-control-container"><div class="leaflet-top leaflet-left"><div class="leaflet-control-zoom leaflet-control"><a class="leaflet-control-zoom-in" href="#" title="Zoom in"></a><a class="leaflet-control-zoom-out" href="#" title="Zoom out"></a></div></div><div class="leaflet-top leaflet-right"></div><div class="leaflet-bottom leaflet-left"></div><div class="leaflet-bottom leaflet-right"><div class="leaflet-control-attribution leaflet-control">Powered by <a href="http://leaflet.cloudmade.com">Leaflet</a></div></div><div class="leaflet-top leaflet-center"><div class="leaflet-control-geosearch leaflet-control"><input id="leaflet-control-geosearch-qry" type="text" placeholder="search for address..."><div id="leaflet-control-geosearch-msg" class="leaflet-control-geosearch-msg"><ul id="leaflet-control-geosearch-results"></ul></div></div></div></div><div class="leaflet-map-pane" style="-webkit-transform: translate3d(0px, 0px, 0);"><div class="leaflet-tile-pane"><div class="leaflet-layer"><div class="leaflet-tile-container leaflet-zoom-animated"></div><div class="leaflet-tile-container leaflet-zoom-animated"><img class="leaflet-tile leaflet-tile-loaded" style="height: 256px; width: 256px; left: 980px; top: 406px;" src="http://c.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/13/4304/2940.png"><img class="leaflet-tile leaflet-tile-loaded" style="height: 256px; width: 256px; left: 724px; top: 406px;" src="http://b.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/13/4303/2940.png"><img class="leaflet-tile leaflet-tile-loaded" style="height: 256px; width: 256px; left: 724px; top: 150px;" src="http://a.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/13/4303/2939.png"><img class="leaflet-tile leaflet-tile-loaded" style="height: 256px; width: 256px; left: 980px; top: 150px;" src="http://b.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/13/4304/2939.png"><img class="leaflet-tile leaflet-tile-loaded" style="height: 256px; width: 256px; left: 980px; top: 662px;" src="http://a.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/13/4304/2941.png"></div></div></div><div class="leaflet-objects-pane"><div class="leaflet-shadow-pane"></div><div class="leaflet-overlay-pane"></div><div class="leaflet-marker-pane"></div><div class="leaflet-popup-pane"></div></div></div><div class="leaflet-control-container"><div class="leaflet-top leaflet-left"><div class="leaflet-control-zoom leaflet-bar leaflet-control"><a class="leaflet-control-zoom-in" href="#" title="Zoom in">+</a><a class="leaflet-control-zoom-out" href="#" title="Zoom out">-</a></div></div><div class="leaflet-top leaflet-right"></div><div class="leaflet-bottom leaflet-left"></div><div class="leaflet-bottom leaflet-right"><div class="leaflet-control-attribution leaflet-control"><a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a> | Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a></div></div></div></div><script src="leaflet.js"></script><script src="https://maps.gstatic.com/intl/it_it/mapfiles/api-3/13/14/main.js"></script>
<script>window.onload = function () {function getURLParameter(name) {return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,])[1]);}var regionParameter = getURLParameter('region');var region = (regionParameter === 'undefined') ? '' : regionParameter;
var map = L.map('map').setView([45.202934, 9.137108], 13);L.tileLayer('http://{s}.tile.cloudmade.com/afda1fc8c23548c28eeb256f3e08707c/997/256/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',maxZoom: 18}).addTo(map);
new L.Control.GeoSearch({provider: new L.GeoSearch.Provider.Google({region: region})}).addTo(map);};</script>
</body></html>Thanks!
--
---
You received this message because you are subscribed to a topic in the Google Groups "Leaflet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leaflet-js/xSC34CQY_yw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.