|
@@ -6,7 +6,7 @@ $(document).ready(function () {
|
|
|
geocoder = new google.maps.Geocoder();
|
|
|
|
|
|
map.addControl(new L.Control.Search({
|
|
|
- sourceData: googleGeocoding,
|
|
|
+ sourceData: apiGoogleGeocoding,
|
|
|
formatData: formatJSON,
|
|
|
markerLocation: true,
|
|
|
autoType: true,
|
|
@@ -78,17 +78,30 @@ function setDataValue() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function googleGeocoding(text, callResponse) {
|
|
|
- geocoder.geocode({address: text}, callResponse);
|
|
|
+function apiGoogleGeocoding(text, callResponse){
|
|
|
+ $.ajax({
|
|
|
+ type: "GET",
|
|
|
+ data: {
|
|
|
+ address: text
|
|
|
+ },
|
|
|
+ url: '/api/geocode',
|
|
|
+ success: function (retorno){
|
|
|
+ callResponse(retorno);
|
|
|
+ },
|
|
|
+ dataType: "json"
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function formatJSON(rawjson) {
|
|
|
var json = {},
|
|
|
key;
|
|
|
- for (var i in rawjson) {
|
|
|
- key = rawjson[i].formatted_address;
|
|
|
- loc = new L.latLng(rawjson[i].geometry.location.lat(), rawjson[i].geometry.location.lng());
|
|
|
- json[key] = loc;
|
|
|
+
|
|
|
+ if(rawjson != null && rawjson.results){
|
|
|
+ for (var i in rawjson.results) {
|
|
|
+ key = rawjson.results[i].formatted_address;
|
|
|
+ loc = new L.latLng(rawjson.results[i].geometry.location.lat, rawjson.results[i].geometry.location.lng);
|
|
|
+ json[key] = loc;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return json;
|
|
@@ -101,18 +114,25 @@ function formatJSON(rawjson) {
|
|
|
* @param callback Funcion de callback el primer parametro contiene el status y el segundo un objeto json.
|
|
|
*/
|
|
|
function geocodeLatLng(lat, lng, callback) {
|
|
|
- var latlng = {lat: lat, lng: lng};
|
|
|
- geocoder.geocode({'location': latlng}, function (results, status) {
|
|
|
- if (status == google.maps.GeocoderStatus.OK) {
|
|
|
- if (results[0]) {
|
|
|
- callback(true, {
|
|
|
- complete: results[0].formatted_address
|
|
|
- });
|
|
|
- } else {
|
|
|
- callback(false, status.status);
|
|
|
+ $.ajax({
|
|
|
+ type: "GET",
|
|
|
+ data: {
|
|
|
+ latLng: lat + "," + lng
|
|
|
+ },
|
|
|
+ url: '/api/geocode',
|
|
|
+ success: function (result){
|
|
|
+ if(result.status == google.maps.GeocoderStatus.OK){
|
|
|
+ if(result.results[0]){
|
|
|
+ callback(true, {
|
|
|
+ complete: result.results[0].formatted_address
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ callback(false, result.status);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ callback(false, result.status);
|
|
|
}
|
|
|
- } else {
|
|
|
- callback(false, status.status);
|
|
|
- }
|
|
|
+ },
|
|
|
+ dataType: "json"
|
|
|
});
|
|
|
}
|