-
Improvement
-
Resolution: Fixed
-
Minor
-
3.6, 3.7, 4.1
-
MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_401_STABLE
-
MOODLE_403_STABLE
-
MDL-63759-master -
Hi,
I would like to propose a quick enhancement code for iplookup/index.php.
In the code there is 2 ways to show geoip lookup, on a static image or on a google maps if you have api keys. This way we can use openstreetmap-based maps instead of google.
To achieve this we can replace google maps code to this code:
Old code:
if (is_https()) { |
$PAGE->requires->js(new moodle_url('https://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false'))); |
} else { |
$PAGE->requires->js(new moodle_url('http://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false'))); |
}
|
|
$module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js'); |
$PAGE->requires->js_init_call('M.core_iplookup.init3', array($info['latitude'], $info['longitude'], $ip), true, $module); |
echo '<div id="map" style="width: 650px; height: 360px"></div>'; |
echo '<div id="note">'.$info['note'].'</div>'; |
New code:
$lon = $info['longitude']; |
$lat = $info['latitude']; |
|
//bounding box calculation to set the initial "zoom level" on the map:
|
|
$bboxleft = $lon-1.8270; |
$bboxbottom = $lat-1.0962; |
$bboxright = $lon+1.8270; |
$bboxtop = $lat+1.0962; |
|
echo '<div id="map" style="width: 610px; height: 310px">'; |
echo '<object data="https://www.openstreetmap.org/export/embed.html?bbox='.$bboxleft.'%2C'.$bboxbottom.'%2C'.$bboxright.'%2C'.$bboxtop.'&layer=mapnik&marker='.$lat.'%2C'.$lon.'" width="100%" height="100%"></object>'; |
echo '</div>'; |
echo '<div id="note">'.$info['note'].'</div>'; |
To test my version all you need is to write something into the api key field at admin -> settings -> location settings.
I also attached the whole php file for evaluation.
What is your thoughts?
Peter
- has been marked as being related by
-
MDL-77036 core_iplookup_geoplugin_testcase::test_ipv4() started failing again
-
- Closed
-
-
MDL-68399 Bug on showing marker in map
-
- Closed
-
- has to be done before
-
MDL-78372 Since Google Maps has been replaced with OpenStreetMaps, $CFG->googlemapkey3 and the Site administration setting can be removed
-
- Closed
-