Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getmap initialization issue #434

Closed
celron opened this issue Mar 7, 2015 · 9 comments
Closed

getmap initialization issue #434

celron opened this issue Mar 7, 2015 · 9 comments

Comments

@celron
Copy link
Contributor

celron commented Mar 7, 2015

Greetings,
I have been utilizing the map plugin successfully, and have started playing with options. with getmap()

                    var mapProp2 = {'backgroundColor': 'white',
                        'mapType': plugin.google.maps.MapTypeId.ROADMAP,
                        'controls': {
                            'compass': true,
                            'myLocationButton': true,
                            'indoorPicker': true,
                            'zoom': true
                        },
                        'gestures': {
                            'scroll': true,
                            'tilt': true,
                            'rotate': true
                        },
                        //fix for camera on iphone... always zoomed out if this is not set.
                        'camera': {
                            'zoom': 15 
                        }};
                map = plugin.google.maps.Map.getMap(mapDiv, mapProp2);

The map will not appear and will generate an error
03-07 11:01:53.327: D/CordovaLog(7935): file:///android_asset/www/plugins/plugin.google.maps/www/googlemaps-cdv-plugin.js: Line 115 : 'getMap' is not defined in GoogleMaps plugin.

If I remove the 'camera' : { 'zoom': 15} option, then the map will appear, which is easy enough, however I would like to know if I'm doing something wrong.

Am I allowed to initialize the camera in the getMap() or do I have to do that after the MAP_READY has fired?

@wf9a5m75
Copy link
Member

wf9a5m75 commented Mar 7, 2015

I tested your code, but the issue is not reproduced.

@celron
Copy link
Contributor Author

celron commented Mar 8, 2015

Which version did you test against? I'm using cordova 4.2 with the release version of the plugin.

@wf9a5m75
Copy link
Member

wf9a5m75 commented Mar 8, 2015

Ok, I confirmed your issue, but it is already fixed in the test branch.
New version will be available in couple of days.
Use the test branch, or wait until the release.

In order to use the test branch, install git command, then

$> cordova plugin rm plugin.google.maps
$> rm -rf platforms/ios/(your app)/plugins/com.googlemaps.ios/
$> rm -rf platforms/ios/(your app)/plugins/plugin.google.maps/
$> cordova plugin add https://github.com/wf9a5m75/phonegap-googlemaps-plugin#test --variable API_KEY_FOR_ANDROID=... --variable API_KEY_FOR_IOS=...

@wf9a5m75 wf9a5m75 closed this as completed Mar 8, 2015
@wf9a5m75 wf9a5m75 added this to the v1.2.5 milestone Mar 8, 2015
@wf9a5m75 wf9a5m75 added the bug label Mar 8, 2015
@celron
Copy link
Contributor Author

celron commented Mar 8, 2015

Thank you very much for your attention to this.

@bradmarder
Copy link

This issue still exists with the latest version 1.3.1 (tested on Android, samsung s4)

Everything worked perfectly invoking getMap() with no options. As soon as I passed the following options, I received the error 'getMap' is not defined in GoogleMaps plugin.

var options = {
  camera: {
    latLng: latLongs // an array of LatLng objects
  }
};

plugin.google.maps.Map.getMap(options);

@hirbod
Copy link
Contributor

hirbod commented Oct 11, 2015

@bradmarder yes, because getMap need a specified container

The first argument of getMap can not be an object.

var div = document.getElementById("map");
var map;

var options = {
  camera: {
    latLng: latLongs // an array of LatLng objects
  }
};       

// Initialize the map view
map = plugin.google.maps.Map.getMap(div, options);

@DrMoriarty
Copy link

The bug still exists:

plugin.google.maps.Map.getMap(document.getElementById('map_canvas'))

'getMap' is not defined in GoogleMaps plugin. console-via-logger.js:173

plugin.google.maps 1.3.9 "phonegap-googlemaps-plugin"
bash-3.2$ ionic --version
1.7.11
bash-3.2$ cordova --version
5.4.1
Android 4.4.2

@iori57
Copy link

iori57 commented Jun 8, 2016

I ran into this issue but for my case I defined my API_KEY metadata in the wrong section in the android manifest file

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBGJt68QCV...CuzkHNimuiQWY" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Make sure these two entries is within the tags inside android manifest and not outside of it. Having it outside or not at all will get the error 'getMap' is not defined in GoogleMaps plugin.

The plugin gives a popup warning if API_KEY is not equal to API_KEY_FOR_ANDROID, but perhaps it should check for null or empty API_KEY as well and pop up an appropriate message. For my case my API_KEY is null.

Try to put a breakpoint at line 432 to see if you are able to get the API_KEY, if you can then it is a different issue already.

Hope this helps someone.

@alex116
Copy link

alex116 commented Jul 1, 2016

Would someone please update this tutorial example?
https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Map.getMap()#create-a-map-with-initialize-options

It seems to initialize getMap() with the options and is missing the DOM element just like what is seen in
this comment above by bradmarder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants