avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

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?

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Hide google map until it is fully ready

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

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

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?

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Hide google map until it is fully ready

Hello! Did you try to test on device?

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Hide google map until it is fully ready

Hi,

What is the Android version you use?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Hide google map until it is fully ready

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

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

Android 4.3

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Hide google map until it is fully ready

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.

Return to “Issues”