Page 1 of 2

Hide google map until it is fully ready

Posted: Fri Dec 20, 2013 8:52 am
by avdhooft

How can I hide a google map until it is fully ready?
I use the following code at "page show":
code
setTimeout( function(){
var myOptions = { zoom :16, center: new google.maps.LatLng(newLat, newLng), mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map($('div[dsid="Kaart"]').get(0), myOptions);
var sfLatlng = new google.maps.LatLng(newLat, newLng);
var marker = new google.maps.Marker({ position: sfLatlng, map: map, title: var2 });
}, 1000);
/code

The code works fine, but the result is that you first see a map on the location that is set in the map properties. When the timer is finished the map is moved to the correct location. Without the delay it does not work (map not ready?).
I tried hiding the map at page load an show again when the marker is set. Hiding is no problem, but showing again did not work (Appery('Kaart').show();).

How can I do this?


Hide google map until it is fully ready

Posted: Fri Dec 20, 2013 9:41 am
by Oleg Danchenkov

Hi.
Try this
code$('[dsid="Kaart"]').show();/code


Hide google map until it is fully ready

Posted: Sat Dec 21, 2013 7:45 am
by avdhooft

The show works, but it introduced an other problem. The map is not loaded completely and is also centered on the wrong location. Also zooming out/in still does not load the map completely. The marker is on the left top part of the map and is just out of viewing scope.

Image

I use a 'setproperty' at 'page show' to hide the map, and the following code (also 'page show'):
code
setTimeout( function(){
var myOptions = { zoom :16, center: new google.maps.LatLng(newLat, newLng), mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map($('div[dsid="Kaart"]').get(0), myOptions);
var sfLatlng = new google.maps.LatLng(newLat, newLng);
var marker = new google.maps.Marker({ position: sfLatlng, map: map, title: var2 });
$('[dsid="Kaart"]').show();
}, 1000);
/code

Before adding the hide map and the "$('[dsid="Kaart"]').show();" the map was loaded completely and centered correctly. I also tried with '$('[dsid="Kaart"]').hide();', but this does not help. Not hiding the map and keeping the "$('[dsid="Kaart"]').show();" code in loads and centers the map corectly but is not the behaviour I want (first a 'wrong' map is shown and when the timer ands the correct map is shown).

How can this be solved?


Hide google map until it is fully ready

Posted: Sat Dec 21, 2013 1:37 pm
by avdhooft

I have shared the app already with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.
Image


Hide google map until it is fully ready

Posted: Sat Dec 21, 2013 2:43 pm
by Alena Prykhodko

Hello! Did you try to test on device?


Hide google map until it is fully ready

Posted: Sun Dec 22, 2013 5:52 pm
by avdhooft

Yes. I tested it on a samsung android phone.
Similar result. Maps is only partly loaded and the marker is on the top left of the map just outside the viewing area.


Hide google map until it is fully ready

Posted: Mon Dec 23, 2013 8:10 am
by Kateryna Grynko

Hi,

What is the Android version you use?


Hide google map until it is fully ready

Posted: Mon Dec 23, 2013 4:06 pm
by Maryna Brodina

Hello! After pre$('[dsid="Kaart"]').show();/pre add the following line pregoogle.maps.event.trigger(map, "resize");/pre


Hide google map until it is fully ready

Posted: Tue Dec 24, 2013 6:59 am
by avdhooft

Android 4.3


Hide google map until it is fully ready

Posted: Tue Dec 24, 2013 7:02 am
by avdhooft

Thanks!

I'm almost there: the map is now fully loaded. It is only not centered at the correct location. It should be centered around the marker, but the marker is just out of scope on the top left part of the map. The "test" in the browser and on the phone give similar result.