Gmap3 - Forum

Gmap3 exchange platform

You are not logged in.

Ads
(server costs 27.50€ per month)


#1 2011-11-29 14:27:08

Tijmen
Member
Registered: 2011-11-29
Posts: 11

setCenter after resizing the map

I have a small map in the corner of an article, and when a user clicks on the expand link the width is set to 100%. This works fine, but it doesn't reset the center of the map. So I found this code that should refocus the center again.


This is from the php file

$nwm_MapID.gmap3({action: 'setCenter', args:[<?php echo $latlng[0];?>,<?php echo $latlng[1]; ?>]});

And in the html becomes this.

$nwm_MapID.gmap3({action: 'setCenter', args:[48.86745543642139,  2.1407350835937677]});

But when I click on the resize link, there is a js error.  It only seems to recieve one part of the latlng value?

Error: Invalid value for property <center>: 48.86745543642139
Source File: http://maps.gstatic.com/intl/en_us/mapfiles/api-3/7/3/main.js
Line: 28

On http://gmap3.net/documentation.html is an example showing 'args:[ result[0].geometry.location ]'. I tried that example and showed the content of the result[0].geometry.location with an alert, and its the same latlng format I have. But mine doesn't work.

I'm clearly overlooking something here, but not sure what smile

Offline

Ads
(server costs 27.50€ per month)


#2 2011-11-29 16:12:38

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: setCenter after resizing the map

args is an array, and latLng needs to be array also

args[ [48.86745543642139,  2.1407350835937677] ]

Offline

#3 2011-11-29 16:49:28

Tijmen
Member
Registered: 2011-11-29
Posts: 11

Re: setCenter after resizing the map

I still get an error sad It does contains both values now, instead of just 1

Error: Invalid value for property <center>: 48.86745543642139,2.1407350835937677
Source File: http://maps.gstatic.com/intl/en_us/mapfiles/api-3/7/3/main.js
Line: 28

Offline

#4 2011-11-29 17:04:06

Tijmen
Member
Registered: 2011-11-29
Posts: 11

Re: setCenter after resizing the map

Could it be that there is something wrong with the setCenter action in gmap3?

I tried this example code, and the result[0].geometry.location does show content with alert, but it never centers the map?

$('#test').gmap3(
{ action: 'getLatLng',
address: '2 bis rue saint antoine, eguilles',
callback: function(result){
if (result){
$(this).gmap3({action: 'setCenter', args:[ result[0].geometry.location ]});
} else {
alert('Bad address 2 !');
}
}
}
);

Offline

#5 2011-11-29 18:32:43

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 580

Re: setCenter after resizing the map

Hi,

When you use args, it means this a pure google.maps function

In this case (only), you have to use pure google.maps objects :

$nwm_MapID.gmap3({action: 'setCenter', args:[new google.maps.LatLng (<?php echo $latlng[0];?>,<?php echo $latlng[1]; ?>)]});

more clear :

var latLng = new google.maps.LatLng (<?php echo $latlng[0];?>,<?php echo $latlng[1]; ?>);
$nwm_MapID.gmap3({action: 'setCenter', args:[latLng]});

or my choice :

var latLng = new google.maps.LatLng (<?php echo implode(',', $latlng) ?>);
$nwm_MapID.gmap3("get").setCenter(latLng);

This latest is the easiest to understand : get return the pure google.maps.Map and setCenter in call on it

The gmap3 framework can't parse all the google maps functions (update in it are made every days, and it's really too huge)

Have a look on this (updated) documentation

Offline

#6 2011-11-30 02:23:36

Tijmen
Member
Registered: 2011-11-29
Posts: 11

Re: setCenter after resizing the map

I see what I did wrong now smile No more errors, but it still doesn't zoom sad The same with the example from the documentation. When I do alert(latLng) the right value shows up, but it doesn't zoom or in my case refocus the map

Offline

#7 2011-11-30 19:07:06

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 580

Re: setCenter after resizing the map

post your latest code please

Offline

#8 2011-12-01 11:39:24

Tijmen
Member
Registered: 2011-11-29
Posts: 11

Re: setCenter after resizing the map

This is my code now. Before I click the expand button it works fine, it adds the marker and centers the map. The problem is just that it doesn't refocus after expanding the map.

This is what view source shows in firefox.

$(document).ready(function() {

	$nwm_MapID = $("#gmap-nwm");
	$nwm_map_org_width = $nwm_MapID.width();
		
	$nwm_MapID.gmap3(
	{ action:'init',
	  options:{
		  center:[52.5234051,  13.411399899999992],
		  zoom: 8
		}
	},
	{ action: 'addMarker',
		latLng:[52.5234051,  13.411399899999992],
		options:{
		  draggable: false,
		},
	});
	
	$nwm_MapID.append('<div id="expand-nwm"><a href="#">Expand</a></div>')	
	$("#expand-nwm").toggle(
      function () {
		$nwm_MapID.css('width','100%');
		$("#expand-nwm").html('<a href="#">Shrink</a>');
		var latLng = new google.maps.LatLng (52.5234051,  13.411399899999992);
		$nwm_MapID.gmap3("get").setCenter(latLng);
      },
      function () {
		$nwm_MapID.css('width',$nwm_map_org_width);
		$("#expand-nwm").html('<a href="#">Expand</a>');
      }
    );
		
});

Offline

#9 2011-12-01 13:09:53

kirk
Member
Registered: 2011-11-23
Posts: 13

Re: setCenter after resizing the map

Hi,

Could you give the code html please ?

K.

Offline

#10 2011-12-01 13:21:50

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: setCenter after resizing the map

if you resize the container of the map, you need to trigger google maps API resize() so map knows what has happened.
http://code.google.com/apis/maps/docume … e.html#Map
look at Events/ resize for explanation

$(mapSelector).gmap3({action: 'resize'})

Offline

#11 2011-12-01 14:16:21

kirk
Member
Registered: 2011-11-23
Posts: 13

Re: setCenter after resizing the map

So, it should be like this :

google.maps.event.trigger($(mapSelector).gmap3("get"), "resize") ;

Offline

#12 2011-12-02 04:47:53

Tijmen
Member
Registered: 2011-11-29
Posts: 11

Re: setCenter after resizing the map

Thanks for all the help, it works fine now smile

Offline

#13 2016-03-18 06:09:05

waleeed00
Member
Registered: 2016-03-18
Posts: 1

Re: setCenter after resizing the map

I tried this example code, and the result[0].geometry.location does show content with alert, but it never centers the map?

Last edited by waleeed00 (2016-03-30 08:26:10)

Offline

#14 2016-11-24 17:25:50

Andrewsep
Member
From: Malawi
Registered: 2016-11-19
Posts: 11
Website

Re: setCenter after resizing the map

I have also encountered this bug. Stopped playing after it. Skyranger or how is it called was near the edge of the map, on the road.

Offline

#15 2016-11-27 21:55:48

Andrewsep
Member
From: Malawi
Registered: 2016-11-19
Posts: 11
Website

Re: setCenter after resizing the map

also i have very bright light from the fire
is it normal ?
my eyes bleed when I look at the bright fire

Offline

#16 2017-08-06 16:13:33

ronnykinge
Member
Registered: 2017-04-06
Posts: 2,386

Re: setCenter after resizing the map

a website or app, these simple templates are designed to help you sketch your.  thesis writer hire  nition that pharmacists, as well as doctors and nurses (and indeed all. Resume Skills: List of Skills for Verbal and written communication, client & partner relationship management, business development, high touch. 
Talk about it as if it was the most interesting thing in the world.  best dissertation helper  Philadelphia, Read the instructions how to write it better. How To Start A Career In The Oil And Gas Industry: What Employers. A Bundle forming a mapping of potential target package names to different extras Bundles to add Most values here depend on the type of component being. 
Summerhill School in Suffolk is one of Britain's most famous schools.  discovery education homework help home  Studies dissertation topics in business practice, marketing, for your mba dissertation in professional management in which a. NAFTA opened the US's door to drugs from Mexico, mixing them. for a specialization in finance because money makes the word.

Offline

Board footer

Powered by FluxBB