Cordova-plugin-googlemaps: destroy map object

Created on 11 Aug 2014  Â·  28Comments  Â·  Source: mapsplugin/cordova-plugin-googlemaps

i presumed map is cached in phone memory... is this a way to destroy the map completely at certain event say logout event of my application

Most helpful comment

I added map.remove() method which destroys the map object completely.
In order to use this method, you need to update the plugin.

$> cordova plugin rm plugin.google.maps
$> cordova plugin add plugin.google.maps --variable API_KEY_FOR_ANDROID= ... --variable API_KEY_FOR_IOS=...

All 28 comments

There is no way currently.
But map.clear() removes all objects and event listeners.

Ok thanks....does map keep its data in cache or localstorage... will try to remove from there

What data do you want to remove?
This plugin does not use local storage or cache.

oh ok...i looking for a way to remove loaded map when my app is logged out

On Tue, Aug 12, 2014 at 9:55 PM, Masashi Katsumata <[email protected]

wrote:

What data do you want to remove?
This plugin does not use local storage or cache.

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-51938985
.

How about this way: map.clear() then map.setDiv(nulll)?

yes i used it to destroy the map's child and div what i feel is the second
time map is not loading freshly even though i load it in the code
explicitly and it is coming from cache that time. sometime when my
application was open and move with my phone in the new place it shows new
marker(locate your curr location) with the old one ...

On Wed, Aug 13, 2014 at 9:34 PM, Masashi Katsumata <[email protected]

wrote:

How about this way: map.clear() then map.setDiv(nulll)?

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-52069956
.

So the problem is that current your location is old when you open the map second time?
Do you use map.getMyLocation() currently?

Yes i used it.... even if move a bit away from the location with the
application open and reload the page it shows two markers some times

On Wed, Aug 13, 2014 at 10:53 PM, Masashi Katsumata <
[email protected]> wrote:

So the problem is that current your location is old when you open the map
second time?
Do you use map.getMyLocation() currently?

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-52080718
.

map.getMyLocation() uses LocationClient.getLastLocation() internally due to save the battery.
It means it returns old location sometimes.
So if you want to get real current location, please use other ways currently.
See https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/96

Thank you.will try the same.
I got one more issue in ios(ver 7).i am using location marker. on click of
marker i show the popup(canvas).
if i click those markers repeatedly the application get crashed...this
happens only in IOS and clicking on marker. seems at this moment the map
object destroyed completely . any suggestions?

On Wed, Aug 13, 2014 at 11:55 PM, Masashi Katsumata <
[email protected]> wrote:

map.getMyLocation() uses LocationClient.getLastLocation() internally due
to save the battery.
It means it returns old location sometimes.
So if you want to get real current location, please use other ways
currently.
See #96 https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/96

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-52089381
.

Could you give me some code for test?

I added map.remove() method which destroys the map object completely.
In order to use this method, you need to update the plugin.

$> cordova plugin rm plugin.google.maps
$> cordova plugin add plugin.google.maps --variable API_KEY_FOR_ANDROID= ... --variable API_KEY_FOR_IOS=...

cool. will try thank you

On Fri, Aug 29, 2014 at 10:28 PM, Masashi Katsumata <
[email protected]> wrote:

Closed #169
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169.

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#event-159069508
.

So i attempted the map.remove() on my object and it is not removing the map at all. Is there another key piece that i am missing in order to complete this?

@OSFalcon0928 What the plugin version do you use?, And what the os do you use, Android version or iOS version?

I am currently using the one that is on the https://github.com/wf9a5m75/phonegap-googlemaps-plugin website under the download zip. This is for the Android Version.

Is there any error messages in Logcat

yeah. the one that stands out to me is this one:

W/System.err(22921): java.lang.IllegalArgumentException: remove is not a constant in plugin.google.maps.GoogleMaps$METHODS
W/System.err(22921): at java.lang.Enum.valueOf(Enum.java:198)
W/System.err(22921): at plugin.google.maps.GoogleMaps$METHODS.valueOf(GoogleMaps.java:95)
W/System.err(22921): at plugin.google.maps.GoogleMaps$1.run(GoogleMaps.java:151)
W/System.err(22921): at android.os.Handler.handleCallback(Handler.java:733)
W/System.err(22921): at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err(22921): at android.os.Looper.loop(Looper.java:157)
W/System.err(22921): at android.app.ActivityThread.main(ActivityThread.java:5356)
W/System.err(22921): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(22921): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(22921): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
W/System.err(22921): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
W/System.err(22921): at dalvik.system.NativeStart.main(Native Method)
W/qdhwcomposer( 284): Excessive delay reading vsync: took 6133 ms

And the way i am calling it is newmap.vm.Map.remove();

I can't understand your code.
newmap.vm.Map.remove();

map.remove() is not Map.remove()
On Sep 11, 2014 7:21 AM, "OSFalcon0928" [email protected] wrote:

yeah. the one that stands out to me is this one:

W/System.err(22921): java.lang.IllegalArgumentException: remove is not a
constant in plugin.google.maps.GoogleMaps$METHODS
W/System.err(22921): at java.lang.Enum.valueOf(Enum.java:198)
W/System.err(22921): at
plugin.google.maps.GoogleMaps$METHODS.valueOf(GoogleMaps.java:95)
W/System.err(22921): at
plugin.google.maps.GoogleMaps$1.run(GoogleMaps.java:151)
W/System.err(22921): at android.os.Handler.handleCallback(Handler.java:733)
W/System.err(22921): at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err(22921): at android.os.Looper.loop(Looper.java:157)
W/System.err(22921): at
android.app.ActivityThread.main(ActivityThread.java:5356)
W/System.err(22921): at java.lang.reflect.Method.invokeNative(Native
Method)
W/System.err(22921): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(22921): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
W/System.err(22921): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
W/System.err(22921): at dalvik.system.NativeStart.main(Native Method)
W/qdhwcomposer( 284): Excessive delay reading vsync: took 6133 ms

And the way i am calling it is newmap.vm.Map.remove();

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-55270398
.

Can you share me the code how you do create the map?
On Sep 11, 2014 7:26 AM, "Masashi.K" [email protected] wrote:

I can't understand your code.
newmap.vm.Map.remove();

map.remove() is not Map.remove()
On Sep 11, 2014 7:21 AM, "OSFalcon0928" [email protected] wrote:

yeah. the one that stands out to me is this one:

W/System.err(22921): java.lang.IllegalArgumentException: remove is not a
constant in plugin.google.maps.GoogleMaps$METHODS
W/System.err(22921): at java.lang.Enum.valueOf(Enum.java:198)
W/System.err(22921): at
plugin.google.maps.GoogleMaps$METHODS.valueOf(GoogleMaps.java:95)
W/System.err(22921): at
plugin.google.maps.GoogleMaps$1.run(GoogleMaps.java:151)
W/System.err(22921): at
android.os.Handler.handleCallback(Handler.java:733)
W/System.err(22921): at
android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err(22921): at android.os.Looper.loop(Looper.java:157)
W/System.err(22921): at
android.app.ActivityThread.main(ActivityThread.java:5356)
W/System.err(22921): at java.lang.reflect.Method.invokeNative(Native
Method)
W/System.err(22921): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(22921): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
W/System.err(22921): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
W/System.err(22921): at dalvik.system.NativeStart.main(Native Method)
W/qdhwcomposer( 284): Excessive delay reading vsync: took 6133 ms

And the way i am calling it is newmap.vm.Map.remove();

—
Reply to this email directly or view it on GitHub
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/issues/169#issuecomment-55270398
.

sure. here is the snippet on creating the map:

if (mapPosition) {

            mapOptions['camera'] = {
                'latLng': new plugin.google.maps.LatLng(mapPosition.target.lat, mapPosition.target.lng),
                'tilt': mapPosition.tilt,
                'zoom': mapPosition.zoom,
                'bearing': mapPosition.bearing
            }
        }

        newMapVM.Map = plugin.google.maps.Map.getMap(mapOptions);

essentially i am creating a view model and storing the Map object created in the plugin into an object called .Map in my viewmodel. This in turn loads the map onto the screen by using:

newmapVM.Map.setDiv(newmapVM.mapDiv);

I wonder how did you install the plugin. Because the error line number does not match with the current code.
For example,

The error log says:
There is METHODS.valueOf() at line 95 in GoogleMaps.java

at plugin.google.maps.GoogleMaps$METHODS.valueOf(**GoogleMaps.java:95**)

However METHODS.valueOf() is at line 189
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L189

Do you use old version?

well i thought i got the latest version but perhaps i did not? I got the zip from the main site. I cannot seem to get $> cordova plugin rm plugin.google.maps
$> cordova plugin add plugin.google.maps --variable API_KEY_FOR_ANDROID= ... --variable API_KEY_FOR_IOS=...

to run for me

Is there a way i can ensure the correct plugin is installed?

Ok, could you confirm the plugin.xml file at line 2?
You can find the version, like below.

<?xml version='1.0' encoding='utf-8'?>
<plugin id="plugin.google.maps" version="1.1.5"

yup. 1.1.4 is what it says

Ok. Now I understand.
The remove method of v1.1.4 occurs the error, because of bug.
The problem was fixed in v1.1.5.

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/commit/4b0491490eff4ddc8e4843850698a68c1045e8bb

Thus, use v1.1.5.

By the way, I'm planing to release the new version: v1.2.0 in couple of days.
It's better than v1.2.0.
Stay tuned for future update on the official community.

ok. so i am using this through vs 2013 and i cannot get the cordova download tool to work. Is there a good guide to installing it through vs?

I'm sorry, but I'm not familiar with visual studio.
(Even I haven't knew you can install the plugin through visual studio)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cedrickbae picture cedrickbae  Â·  4Comments

christoph-puppe picture christoph-puppe  Â·  5Comments

wf9a5m75 picture wf9a5m75  Â·  3Comments

lakano picture lakano  Â·  4Comments

splitice picture splitice  Â·  5Comments