Last active
December 24, 2015 07:19
-
-
Save dkobia/6763262 to your computer and use it in GitHub Desktop.
This is untested, but its a diff for /themes/default/views/reports/submit_edit_js.php. You need to use Google Maps instead of OpenStreetMap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/themes/default/views/reports/submit_edit_js.php b/themes/default/views/reports/submit_edit_js.php | |
index 507195e..2ea862e 100755 | |
--- a/themes/default/views/reports/submit_edit_js.php | |
+++ b/themes/default/views/reports/submit_edit_js.php | |
@@ -676,43 +676,49 @@ | |
*/ | |
function geoCode() | |
{ | |
- $('#find_loading').html('<img src="<?php echo url::file_loc('img')."media/img/loading_g.gif"; ?>">'); | |
- address = $("#location_find").val(); | |
- $.post("<?php echo url::site() . 'reports/geocode/' ?>", { address: address }, | |
- function(data){ | |
- if (data.status == 'success'){ | |
- // Clear the map first | |
- vlayer.removeFeatures(vlayer.features); | |
- $('input[name="geometry[]"]').remove(); | |
- | |
- point = new OpenLayers.Geometry.Point(data.longitude, data.latitude); | |
- OpenLayers.Projection.transform(point, proj_4326,proj_900913); | |
- | |
- f = new OpenLayers.Feature.Vector(point); | |
- vlayer.addFeatures(f); | |
- | |
- // create a new lat/lon object | |
- myPoint = new OpenLayers.LonLat(data.longitude, data.latitude); | |
- myPoint.transform(proj_4326, map.getProjectionObject()); | |
- | |
- // display the map centered on a latitude and longitude | |
- map.setCenter(myPoint, <?php echo $default_zoom; ?>); | |
- | |
- // Update form values | |
- $("#country_name").val(data.country); | |
- $("#latitude").val(data.latitude); | |
- $("#longitude").val(data.longitude); | |
- $("#location_name").val(data.location_name); | |
- } else { | |
- // Alert message to be displayed | |
- var alertMessage = address + " not found!\n\n***************************\n" + | |
- "Enter more details like city, town, country\nor find a city or town " + | |
- "close by and zoom in\nto find your precise location"; | |
- | |
- alert(alertMessage) | |
- } | |
- $('div#find_loading').html(''); | |
- }, "json"); | |
+ geocoder = new google.maps.Geocoder(); | |
+ | |
+ geocoder.geocode( { 'address': address}, function(results, status) { | |
+ if (status == google.maps.GeocoderStatus.OK) { | |
+ // Clear the map first | |
+ vlayer.removeFeatures(vlayer.features); | |
+ $('input[name="geometry[]"]').remove(); | |
+ | |
+ point = new OpenLayers.Geometry.Point(results[0].geometry.location.lon, results[0].geometry.location.lat); | |
+ OpenLayers.Projection.transform(point, proj_4326,proj_900913); | |
+ | |
+ // create a new lat/lon object | |
+ myPoint = new OpenLayers.LonLat(data.longitude, data.latitude); | |
+ myPoint.transform(proj_4326, map.getProjectionObject()); | |
+ | |
+ // display the map centered on a latitude and longitude | |
+ map.setCenter(myPoint, <?php echo $default_zoom; ?>); | |
+ | |
+ // Get the country | |
+ var country = results[0].formatted_address; | |
+ for (var i=0; i < results[0].address_components.length; i++) { | |
+ for (var b=0;b < results[0].address_components[i].types.length;b++) { | |
+ if (results[0].address_components[i].types[b] == "country") { | |
+ | |
+ country = results[0].address_components[i].long_name; | |
+ break; | |
+ } | |
+ } | |
+ } | |
+ | |
+ // Update form values | |
+ $("#country_name").val(country); | |
+ $("#latitude").val(results[0].geometry.location.lat); | |
+ $("#longitude").val(results[0].geometry.location.lon); | |
+ $("#location_name").val(results[0].formatted_address); | |
+ | |
+ } else { | |
+ alert('Geocode was not successful for the following reason: ' + status); | |
+ } | |
+ | |
+ $('div#find_loading').html(''); | |
+ }); | |
+ | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full function at: https://gist.github.com/dkobia/6763274