I want to get visitor's current location without using any server-side service because free versions are too much inaccurate.
So I haven't configured any Smart API service.
I have then created a view that is set to "Center the map on the visitor's current location".
But it didn't work.
I've checked database and my IP's coordinates are present.
Having a look at code, I found 2 strange things that I suspect being a bug:
1. In ip_geoloc_plugin_style_map.inc, method render():
<?php
if ($visitor_marker || $center_option == IP_GEOLOC_MAP_CENTER_ON_VISITOR) {
// Perform database IP lookup as backup/replacement for HTML5 location
$resample = TRUE; // visitor may be moving so ignore existing lat/long
$store = FALSE; // do not store lat/long and city as it will obliterate the reverse-geocoded one
$reverse_geocode = FALSE; // we only need lat/long, not full street address
$visitor_location = ip_geoloc_get_location_by_ip(ip_address(), $resample, $store, $reverse_geocode);
if (isset($visitor_location['latitude']) && isset($visitor_location['longitude'])) {
$center_latlng = array($visitor_location['latitude'], $visitor_location['longitude']);
}
?>$resample is set to TRUE so database is not checked and if there's no server-side fallback, no location is returned.
In such a case, you expect that client-side location will be used afterwards.
But it doesn't:
2. In ip_geo_loc_api.inc, function ip_geoloc_output_map_multi_location():
<?php
if ($visitor_location_gps) {
// End of life for the unified geo.js library. It slows things down and
// has become less relevant as all modern devices support the HTML5/W3C API
// drupal_add_js(IP_GEOLOC_GEO_JS, array('group' => JS_LIBRARY));
drupal_add_js(IP_GEOLOC_GOOGLE_MAPS_GPS, array('group' => JS_LIBRARY));
}
?>Because IP_GEOLOC_GEO_JS is not used any more, nothing happens in ip_geoloc_gmap_multi_loc.js as this file keeps on relying on it!
See:
if (visitorMarker || centerOption == 2) {
// Retrieve visitor's location, fall back on supplied location, if not found.
if (use_gps && typeof(geo_position_js) == 'object' && geo_position_js.init()) {
// Center the map on the user's current location, using the unified API.
geo_position_js.getCurrentPosition(handleMapCenterAndVisitorMarker1, handlePositionError, {enableHighAccuracy: true});
}
else {
// Use supplied visitor lat/lng to center and set marker.
var latLng = settings.ip_geoloc_multi_location_center_latlng;
if (latLng) {
handleMapCenterAndVisitorMarker2(latLng[0], latLng[1]);
}
}
}
Something is definitely broken here.
Comments
Comment #1
rdeboerHello anrikun,
Thanks for your report.
I haven't had time to look at it in detail.
Hope to do that soon.
Rik
Comment #2
rdeboerFixed with latest check-in.
Comment #3
rdeboer