-
Notifications
You must be signed in to change notification settings - Fork 918
Map.getMap()
The Map.getMap()
is a static method. You can grab a map instance.
###Description
The Map.getMap()
method returns an instance of the map class.
The plugin initializes the native SDK and other thing, it takes a few second.
The MAP_READY
event is fired when the map is ready to go.
This plugin generates only one map instance using map.getMap()
method.
In general, you may want to create multiple maps, but this plugin is not possible.
###Code
var map = plugin.google.maps.Map.getMap();
map.addEventListener(plugin.google.maps.event.MAP_READY, function onMapInit(map) {
// The map is initialized, then show a map dialog
map.showDialog();
});
You can initialize the camera view when the map is initialized. This is useful when you want to show the specific location of the map.
const GORYOKAKU_JAPAN = new plugin.google.maps.LatLng(41.796875,140.757007);
var map = plugin.google.maps.Map.getMap({
'mapType': plugin.google.maps.MapTypeId.HYBRID,
'controls': {
'compass': true,
'myLocationButton': true,
'indoorPicker': true,
'zoom': true
},
'gestures': {
'scroll': true,
'tilt': true,
'rotate': true
},
'camera': {
'latLng': GORYOKAKU_JAPAN,
'tilt': 30,
'zoom': 15,
'bearing': 50
}
});
###Embed a map into a div tag You can also implement the map into your app design. Declare the container DOM (such as DIV), then specify it.
<div id='map_canvas' style='width:300px;height:300px'></div>
var div = document.getElementById('map_canvas');
var map = plugin.google.maps.Map.getMap(div);
You must need to understand how to work this feature.
The plugin does not watch any effects for the DOM element, such as CSS position changing, dead or alive.
It means you can just tell the size and the position of the DOM element when you run map.setDiv()
.
If you want to change the position of the map with the DOM element,
you need to call map.refreshLayout()
(Don't too much).
Also, the map draws in the native view over the HTML browser view. This means you can not overlay any HTMLs above the map.
Many CSS frameworks loves CSS transition because it's easy and powerful. But W3C does not define the start event for CSS transition. It means the plugin can not detect when the CSS transition starts.
One of the common questions is How to slide the map with CSS?
.
This plugin does not watch the CSS positions and the above reason,
you need to take care the map position by yourself.
One solution is the hiding and showing. See more the detailed explain in the #50
If you get an error, feel free to ask me on the official community or the issue list.
New version 2.0-beta2 is available.
The cordova-googlemaps-plugin v2.0 has more faster, more features.
https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.0.0/README.md
New versions will be announced through the official community. Stay tune!
Feel free to ask me on the issues tracker.
Or on the official community is also welcome!
New version 2.0-beta2 is available.
The cordova-googlemaps-plugin v2.0 has more faster, more features.
https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.0.0/README.md