Page 1 of 1

Google map not accepting commands

Posted: Tue Feb 25, 2014 9:13 pm
by Larry6621532

I am trying to display the Terrain map as my default but I keep getting an error.

"Uncaught TypeError: Cannot set property 'mapTypeId' of undefined "
"Cannot refresh, map is not initialized! "

It seems that my map does not get initialized
Here is the code.

var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.Terrain
};
// Tried each of these
//var map = new google.maps.Map($('div[dsid="map"]').get(0), mapOptions);
//var map = Appery('map');

var map = new google.maps.Map(Appery('map').get(0), mapOptions);
map.gmap.mapTypeId = google.maps.MapTypeId.Terrain;
map.refresh();

What I really want to do is simply turn off the POI (points of interest) on the map and switching to the Terrain map was a backup. but I figured if I can get the simpler solution working I would take that.

var myMapOptions = {
styles:[{
featureType:"poi",
stylers:[{
visibility:"off"
}]
}]
};

Any ideas greatly appreciated?
Thanks
Larry


Google map not accepting commands

Posted: Tue Feb 25, 2014 10:14 pm
by Kateryna Grynko

Hi Larry,

What is your component name? Please make sure it's named 'map'.


Google map not accepting commands

Posted: Tue Feb 25, 2014 10:23 pm
by Larry6621532

Yes it is called map. Also in the code I posted the word " Terrain" is in lower case but I did try upper case as well. In chrome with debugger showing the console a see errors or warnings that the " Cannot refresh, map is not initialized" 3 times. I only have map.refresh in my code in one place on a geocode success event. I even commented that one out and still get the message.


Google map not accepting commands

Posted: Wed Feb 26, 2014 5:39 am
by Illya Stepanov

Hi Larry,

These things will help to understand:
ol
liGoogle Map component automatically create Google map instance. So you don't have to do it./li

liYou can access Google maps component when it would be initialized./li
/ol

So the code to change TypeId to "TERRAIN" should be:
pre
var onDelay = function(){
if(!Appery("map").gmap)
return window.setTimeout(onDelay, 100);

Code: Select all

 Appery("map").gmap.setMapTypeId(google.maps.MapTypeId.SATELLITE) 

};

onDelay();
/pre


Google map not accepting commands

Posted: Wed Feb 26, 2014 1:19 pm
by Larry6621532

Your code worked perfectly and thanks for the tip on the Google map Instance.

Appery.io support through this forum is excellent.

Thanks again.
Larry