Hi,

When you use the geolocation field as it default is, you see the whole world.
How can you zoom in on a region?

For example, I want the default map on belgium.

I know you can set the settings of that field and fill in a default value. But when I fill in Belgium, the map is zoomed in too much and you don't see belgium, but one city.

Is it possible to change the default map (the whole world) to one region with a particular zoom?

CommentFileSizeAuthor
#17 a.patch602 bytesphrk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druipol’s picture

Hi,

I´m looking for the same. I need an starting area where the the users could set the marking points without zooming to much.
In GMap it could be set an default center and zoom level, without this coordinates being stored in the db as field value. But if I set an default starting point in geolocation field, it is recognized as an certain address and stored in the db if not anyone change it.
That´s not so an could solution.
Any ideas how to change that?

MatthijsG’s picture

This issue prevented me from using Geolocation :-(. Just a simple feature to set the default zoomlevel ..

arx-e’s picture

+1
Just run into the same issue... Showing the whole planet to someone who should locate their school for example sounds very nice from some theoretical point of view but in practice, it is not. :(

druipol’s picture

Ok, I had other thinks I was working on.
But today I turned on looking for this issue.
First I installed the newest dev Version. I examined the ../geolocation/modules/geolocation_googlemaps/geolocation_googlemaps_widget.js
And there I changed the original code:

          // Get default values
          // This might not be necesarry
          // It can always come from e
          lat = $('#geolocation-lat-' + i + ' input').attr('value') == false ? mapDefaults.lat : $('#geolocation-lat-' + i + ' input').attr('value');
          lng = $('#geolocation-lng-' + i + ' input').attr('value') == false ? mapDefaults.lng : $('#geolocation-lng-' + i + ' input').attr('value');
          latLng = new google.maps.LatLng(lat, lng);

          // Set map options
          mapOptions = {
            zoom: 2,
            center: latLng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: (Drupal.settings.geolocation.settings.scrollwheel != undefined) ? Drupal.settings.geolocation.settings.scrollwheel : false
          }

to this one:

          // Get default values
          // This might not be necesarry
          // It can always come from e
          lat = $('#geolocation-lat-' + i + ' input').attr('value') == false ? mapDefaults.lat : $('#geolocation-lat-' + i + ' input').attr('value');
          lng = $('#geolocation-lng-' + i + ' input').attr('value') == false ? mapDefaults.lng : $('#geolocation-lng-' + i + ' input').attr('value');
          latLng = new google.maps.LatLng(lat, lng);
          latLngStart = new google.maps.LatLng(52.014875,8.526966); ; 

          // Set map options
          mapOptions = {
            zoom: 12,
            center: latLngStart,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: (Drupal.settings.geolocation.settings.scrollwheel != undefined) ? Drupal.settings.geolocation.settings.scrollwheel : false
          }

and voila it´s done what I needed.
Ok, it should better being set on an configuration page. Perhaps someone else could give me an hint how to do this. But it´s an quick working hack. :)
Hope this help a bit.

druipol’s picture

Please test this first on an backup or an local site. I don´t know why, but something seems to be broken now on my testsite. :(

johnv’s picture

Title: Change default map » Better default map settings: center + zoom

I think you can already set this in the UI:
- create a views display;
- add the geofield;
- set format to 'Google Map', and go to settings:
-- set map center to '50.85, 4.35'
-- set map zoom to '7'
Save and show the view. Now you see the map of Belgium.

However, it would be nice to have an auto-center feature, either from the current geofields, or a contextual filter.

P.S. The GMap module has a nice macro builder. enable it and go to /map/macro

joachim’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

I think you can already set this in the UI:
- create a views display;

That's about making a View.

This issue is about the settings for the field, so that when a user created a node with a geolocation field, the map is initially showing the general part of the world that is of interest.

For example, if you site was about restaurant reviews in London, you would want the map on a new node form to show the whole of London.

wluisi’s picture

You can alter the javascript using hook_js_alter:

function YOURMODULE_js_alter(&$javascript) {
  $javascript[drupal_get_path('module', 'geolocation') . '/modules/geolocation_googlemaps/geolocation_googlemaps_widget.js']['data'] = drupal_get_path('module', 'YOURMODULE') . '/js/geolocation_googlemaps_widget_custom.js';
} 

Basically, you're just swapping out 'geolocation_googlemaps_widget.js' with your own custom code in 'geolocation_googlemaps_widget_custom.js'.

This way, all the modifications are in your custom code, and you're not altering the module's code at all.

Ddroid_za’s picture

Issue summary: View changes

I am looking for a similar solution.

I need my Co-ordinate picker to focus on the current user's location to help add nearby events. Preferably even using the user lat an long values that I'm getting from IP Geolocation's html5 geo location mechanism. I tried adding the above code in a custom module. Even with hard coded long and lat values it doesn't change.

doitDave’s picture

Category: Support request » Feature request

For most cases, I find the per-field-instance zoom preset sufficient. However, and this also refers to the original issue which is why I add here instead of duplicating: After starting a site which makes heave use of GF (thanks btw again for this overall nice and helpful module), I realize that there is no perfect default setting for all images, not even if per-instance.

Thus I would like to suggest making the zoom level part of the field input widget in some way. This could happen by

a) just storing the actual zoom level from the widget with the other data.
b) allowing for a token in order to use an arbitrary (integer?) field's value, if one is set, to override the default.
c) extending the widget to provide an override option (filled with the default value).

I am willing to try implementing of any of these, if you will, but probably there are further suggestions or remarks before I do.

Personally, I rather dislike a) since the site in question conditionally uses EXIF data to set the field values, and thus the widget does not play an actual role. Then again, it would not hurt to use a value from the actual widget, since it would provide the default anyway (just like now).

So, in a nutshell, I'd like to read some more voices on this before I start. Anyone?

derjochenmeyer’s picture

Sounds like a great suggestion.

Geolocation field wants to be a super light weight solution for storing lat,lng geolocation data mainly. However it makes sense to store additional "meta data" (zoomlevel, accuracy, height, address information, etc.). What about storing all kinds of "meta data" as a serialized array?

If we start storing the zoomlevel maybe it makes sense to implement this for other widget specific data like accuracy and height?

This should of course also be ported to the Drupal 8 version.

juliencarnot’s picture

Regarding the original request and the first comments, I added this code to geolocation.js (in version 8-dev) , which centers the Google geocoder widget's viewport using fitBounds, because setting the center resulted in filling the input fields in some cases... I'm sure it could be much better and of course would be easier to set from the GUI, but if it can help somebody out there...

@@ -165,12 +181,109 @@
 
     map.controls.index = 1;
 
+    //Center the geocoder widget map around France before any value is set
+    var bounds = new google.maps.LatLngBounds();
+    bounds.extend(new google.maps.LatLng(49.31144851208598, 5.882561523437516));
+    bounds.extend(new google.maps.LatLng(43.58174309299269, -1.025098632812501));
+    map.google_map.fitBounds(bounds);
+
     map.google_map.controls[google.maps.ControlPosition.TOP_LEFT].push(map.controls);
 
Avithemapper’s picture

Hi so the last code didn't work for me.
I'm trying to get the geolocation field to start with a view of the UK (zoom 5). When someone selects a location it then zooms in to that location at zoom 9. I've tried changing the lat lng and the zoom levels to uk zoom 5 but this prevents the widget from zooming in. Any help would be much appreciated.

Avi

joan14’s picture

I want the same, set a default zoom for the input field.
Any solutions working?

John Ching’s picture

To change a preset zoom on Geo Location. No need to fiddle with codes. Do this (Drupal 7).

(I assume you have created a geolocation field in your content type and have put in data. However the widget is displaying a wrong zoom every time the map is displayed on your site)

Go to MANAGE DISPLAY of that geolocation field in your particular content type. Change the zoom number in the settings (the little gear symbol at the right hand side).

In other words go to: structure>content types>your content type>manage display>Geolocation field>settings>zoom: xx

Change that and the preset zoom changes.

omkargaonkar’s picture

I had the same issue I just created view
- Added the geolocation field
- Click on FORMAT Geolocation Google Maps API - CommonMap Settings link.
- Uncheck the checkbox Automatically fit map bounds to results. Disregards any set center or zoom.

I try this and it working Hope this help a bit.

phrk’s picture

Component: Google Maps geolocation » Geolocation Field / Backend
FileSize
602 bytes

It can be quite simply solved by modyfing zoom and center options in geolocation_googlemaps_widget.js. See the attached patch. I hope this thread can be marked as [SOLVED].

ChristianAdamski’s picture

Status: Active » Closed (won't fix)

Closing all 7.x issues. It's time.