Update single item GoolgeMap Cluster












6















I am using this libray to cluster GoogleMap in Android. My question is how can I update the single item I have gone through google from yesterday and no answers are there that explains updating single item. I am using websocket in my project so I need to update the data of item that were received from websocket. Look my implementation below.




My concept is doing
mClusterManager.remove(item)
mClusterManager.add(item) + mClusterManager.cluster() whenever I
receive data from websocket.




and hasmap to identify the object on loop while adding to cluseter like : hashmap.put(_id,mClusterItem[i]);



Now, Whenever on websocket data is received I do,



    onDataReceive(String _id,String name, double latlng, ....){
mClusterManager.remove(hashmap.get(_id));

appClusterItem[0] = new AppClusterItem(.....);
mClusterManager.add(appClusterItem[0]) // Here how can I add item
mClusterManager.cluster();
}


However the above code works first when first data receives, then from second time it will just keep adding the marker and fails to remove that means mClusterManager.remove(hasmap.get(_id)) is not found. And appClusterItem[0] is because I cannot use hashmap.get(_id); on above case bacause it give error variable expected. Anyway to remove the same object and add object on that place??










share|improve this question























  • removeItem and addItem Methods are there in ClusterManager class.

    – Pravin Divraniya
    Nov 21 '18 at 7:07











  • Yaa there is but How could it know that which item to remove??

    – Queendevelopers
    Nov 21 '18 at 8:53











  • Check method signature and read document. You will have your answer.

    – Pravin Divraniya
    Nov 21 '18 at 9:19











  • @PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

    – Queendevelopers
    Nov 22 '18 at 9:00











  • Link is there in my first comment.

    – Pravin Divraniya
    Nov 22 '18 at 9:03
















6















I am using this libray to cluster GoogleMap in Android. My question is how can I update the single item I have gone through google from yesterday and no answers are there that explains updating single item. I am using websocket in my project so I need to update the data of item that were received from websocket. Look my implementation below.




My concept is doing
mClusterManager.remove(item)
mClusterManager.add(item) + mClusterManager.cluster() whenever I
receive data from websocket.




and hasmap to identify the object on loop while adding to cluseter like : hashmap.put(_id,mClusterItem[i]);



Now, Whenever on websocket data is received I do,



    onDataReceive(String _id,String name, double latlng, ....){
mClusterManager.remove(hashmap.get(_id));

appClusterItem[0] = new AppClusterItem(.....);
mClusterManager.add(appClusterItem[0]) // Here how can I add item
mClusterManager.cluster();
}


However the above code works first when first data receives, then from second time it will just keep adding the marker and fails to remove that means mClusterManager.remove(hasmap.get(_id)) is not found. And appClusterItem[0] is because I cannot use hashmap.get(_id); on above case bacause it give error variable expected. Anyway to remove the same object and add object on that place??










share|improve this question























  • removeItem and addItem Methods are there in ClusterManager class.

    – Pravin Divraniya
    Nov 21 '18 at 7:07











  • Yaa there is but How could it know that which item to remove??

    – Queendevelopers
    Nov 21 '18 at 8:53











  • Check method signature and read document. You will have your answer.

    – Pravin Divraniya
    Nov 21 '18 at 9:19











  • @PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

    – Queendevelopers
    Nov 22 '18 at 9:00











  • Link is there in my first comment.

    – Pravin Divraniya
    Nov 22 '18 at 9:03














6












6








6








I am using this libray to cluster GoogleMap in Android. My question is how can I update the single item I have gone through google from yesterday and no answers are there that explains updating single item. I am using websocket in my project so I need to update the data of item that were received from websocket. Look my implementation below.




My concept is doing
mClusterManager.remove(item)
mClusterManager.add(item) + mClusterManager.cluster() whenever I
receive data from websocket.




and hasmap to identify the object on loop while adding to cluseter like : hashmap.put(_id,mClusterItem[i]);



Now, Whenever on websocket data is received I do,



    onDataReceive(String _id,String name, double latlng, ....){
mClusterManager.remove(hashmap.get(_id));

appClusterItem[0] = new AppClusterItem(.....);
mClusterManager.add(appClusterItem[0]) // Here how can I add item
mClusterManager.cluster();
}


However the above code works first when first data receives, then from second time it will just keep adding the marker and fails to remove that means mClusterManager.remove(hasmap.get(_id)) is not found. And appClusterItem[0] is because I cannot use hashmap.get(_id); on above case bacause it give error variable expected. Anyway to remove the same object and add object on that place??










share|improve this question














I am using this libray to cluster GoogleMap in Android. My question is how can I update the single item I have gone through google from yesterday and no answers are there that explains updating single item. I am using websocket in my project so I need to update the data of item that were received from websocket. Look my implementation below.




My concept is doing
mClusterManager.remove(item)
mClusterManager.add(item) + mClusterManager.cluster() whenever I
receive data from websocket.




and hasmap to identify the object on loop while adding to cluseter like : hashmap.put(_id,mClusterItem[i]);



Now, Whenever on websocket data is received I do,



    onDataReceive(String _id,String name, double latlng, ....){
mClusterManager.remove(hashmap.get(_id));

appClusterItem[0] = new AppClusterItem(.....);
mClusterManager.add(appClusterItem[0]) // Here how can I add item
mClusterManager.cluster();
}


However the above code works first when first data receives, then from second time it will just keep adding the marker and fails to remove that means mClusterManager.remove(hasmap.get(_id)) is not found. And appClusterItem[0] is because I cannot use hashmap.get(_id); on above case bacause it give error variable expected. Anyway to remove the same object and add object on that place??







java android websocket hashmap markerclusterer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 5:43









QueendevelopersQueendevelopers

6815




6815













  • removeItem and addItem Methods are there in ClusterManager class.

    – Pravin Divraniya
    Nov 21 '18 at 7:07











  • Yaa there is but How could it know that which item to remove??

    – Queendevelopers
    Nov 21 '18 at 8:53











  • Check method signature and read document. You will have your answer.

    – Pravin Divraniya
    Nov 21 '18 at 9:19











  • @PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

    – Queendevelopers
    Nov 22 '18 at 9:00











  • Link is there in my first comment.

    – Pravin Divraniya
    Nov 22 '18 at 9:03



















  • removeItem and addItem Methods are there in ClusterManager class.

    – Pravin Divraniya
    Nov 21 '18 at 7:07











  • Yaa there is but How could it know that which item to remove??

    – Queendevelopers
    Nov 21 '18 at 8:53











  • Check method signature and read document. You will have your answer.

    – Pravin Divraniya
    Nov 21 '18 at 9:19











  • @PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

    – Queendevelopers
    Nov 22 '18 at 9:00











  • Link is there in my first comment.

    – Pravin Divraniya
    Nov 22 '18 at 9:03

















removeItem and addItem Methods are there in ClusterManager class.

– Pravin Divraniya
Nov 21 '18 at 7:07





removeItem and addItem Methods are there in ClusterManager class.

– Pravin Divraniya
Nov 21 '18 at 7:07













Yaa there is but How could it know that which item to remove??

– Queendevelopers
Nov 21 '18 at 8:53





Yaa there is but How could it know that which item to remove??

– Queendevelopers
Nov 21 '18 at 8:53













Check method signature and read document. You will have your answer.

– Pravin Divraniya
Nov 21 '18 at 9:19





Check method signature and read document. You will have your answer.

– Pravin Divraniya
Nov 21 '18 at 9:19













@PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

– Queendevelopers
Nov 22 '18 at 9:00





@PravinDivraniya Thanks for your suggestion but I could not find documentation as you mention, can you link me one??

– Queendevelopers
Nov 22 '18 at 9:00













Link is there in my first comment.

– Pravin Divraniya
Nov 22 '18 at 9:03





Link is there in my first comment.

– Pravin Divraniya
Nov 22 '18 at 9:03












2 Answers
2






active

oldest

votes


















1














I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this:
I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.






share|improve this answer
























  • mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

    – Queendevelopers
    Nov 21 '18 at 8:56











  • I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

    – Vadim Eksler
    Nov 21 '18 at 9:01











  • Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

    – Queendevelopers
    Nov 22 '18 at 8:56











  • only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

    – Vadim Eksler
    Nov 22 '18 at 10:51











  • You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

    – Queendevelopers
    Nov 25 '18 at 6:34





















1














ClusterManager is having removeItem() defined as below



public void removeItem(T item) {
mAlgorithmLock.writeLock().lock();
try {
mAlgorithm.removeItem(item);
} finally {
mAlgorithmLock.writeLock().unlock();
}
}


You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.






share|improve this answer
























  • Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

    – Queendevelopers
    Nov 30 '18 at 9:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405893%2fupdate-single-item-goolgemap-cluster%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this:
I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.






share|improve this answer
























  • mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

    – Queendevelopers
    Nov 21 '18 at 8:56











  • I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

    – Vadim Eksler
    Nov 21 '18 at 9:01











  • Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

    – Queendevelopers
    Nov 22 '18 at 8:56











  • only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

    – Vadim Eksler
    Nov 22 '18 at 10:51











  • You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

    – Queendevelopers
    Nov 25 '18 at 6:34


















1














I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this:
I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.






share|improve this answer
























  • mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

    – Queendevelopers
    Nov 21 '18 at 8:56











  • I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

    – Vadim Eksler
    Nov 21 '18 at 9:01











  • Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

    – Queendevelopers
    Nov 22 '18 at 8:56











  • only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

    – Vadim Eksler
    Nov 22 '18 at 10:51











  • You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

    – Queendevelopers
    Nov 25 '18 at 6:34
















1












1








1







I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this:
I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.






share|improve this answer













I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this:
I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 6:45









Vadim EkslerVadim Eksler

405214




405214













  • mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

    – Queendevelopers
    Nov 21 '18 at 8:56











  • I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

    – Vadim Eksler
    Nov 21 '18 at 9:01











  • Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

    – Queendevelopers
    Nov 22 '18 at 8:56











  • only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

    – Vadim Eksler
    Nov 22 '18 at 10:51











  • You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

    – Queendevelopers
    Nov 25 '18 at 6:34





















  • mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

    – Queendevelopers
    Nov 21 '18 at 8:56











  • I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

    – Vadim Eksler
    Nov 21 '18 at 9:01











  • Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

    – Queendevelopers
    Nov 22 '18 at 8:56











  • only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

    – Vadim Eksler
    Nov 22 '18 at 10:51











  • You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

    – Queendevelopers
    Nov 25 '18 at 6:34



















mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

– Queendevelopers
Nov 21 '18 at 8:56





mCluster.clearItems(); also needs to clear googleMap.clear(); right?? I think this will not be feasible and stablilty while working with large data later on. Currently I am receving about 50 items in second i.e. 50 times clearing items from cluster and adding them all. will this be good for later??

– Queendevelopers
Nov 21 '18 at 8:56













I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

– Vadim Eksler
Nov 21 '18 at 9:01





I not use googleMap.clear(); just cluster clear. I don't know if it will be good for your case. look at here stackoverflow.com/a/22204134/7917629, it can be helpful to change algorithm or writ self algorithm.

– Vadim Eksler
Nov 21 '18 at 9:01













Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

– Queendevelopers
Nov 22 '18 at 8:56





Another trouble I am getting while using clearItems(); and adding them as you suggested is I cannot check InfoWindows is showing or not. Whenever a data is received a InfoWindow is closed !!

– Queendevelopers
Nov 22 '18 at 8:56













only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

– Vadim Eksler
Nov 22 '18 at 10:51





only one Info Window can be open at a time, you can consider using GoogleMap.OnInfoWindowCloseListener to know when an Info Window has been closed

– Vadim Eksler
Nov 22 '18 at 10:51













You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

– Queendevelopers
Nov 25 '18 at 6:34







You may be right, What I mean to say is I am using many markers to display and their Info Window with their values, now when users click on some specific marker the infowindow shows to them, now whenever the data is received the infowindow closes, I know I can use showInfoWindow() for a marker but how could I know, which marker was showing Info before??

– Queendevelopers
Nov 25 '18 at 6:34















1














ClusterManager is having removeItem() defined as below



public void removeItem(T item) {
mAlgorithmLock.writeLock().lock();
try {
mAlgorithm.removeItem(item);
} finally {
mAlgorithmLock.writeLock().unlock();
}
}


You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.






share|improve this answer
























  • Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

    – Queendevelopers
    Nov 30 '18 at 9:49
















1














ClusterManager is having removeItem() defined as below



public void removeItem(T item) {
mAlgorithmLock.writeLock().lock();
try {
mAlgorithm.removeItem(item);
} finally {
mAlgorithmLock.writeLock().unlock();
}
}


You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.






share|improve this answer
























  • Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

    – Queendevelopers
    Nov 30 '18 at 9:49














1












1








1







ClusterManager is having removeItem() defined as below



public void removeItem(T item) {
mAlgorithmLock.writeLock().lock();
try {
mAlgorithm.removeItem(item);
} finally {
mAlgorithmLock.writeLock().unlock();
}
}


You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.






share|improve this answer













ClusterManager is having removeItem() defined as below



public void removeItem(T item) {
mAlgorithmLock.writeLock().lock();
try {
mAlgorithm.removeItem(item);
} finally {
mAlgorithmLock.writeLock().unlock();
}
}


You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 30 '18 at 9:42









Karan MerKaran Mer

4,73032864




4,73032864













  • Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

    – Queendevelopers
    Nov 30 '18 at 9:49



















  • Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

    – Queendevelopers
    Nov 30 '18 at 9:49

















Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

– Queendevelopers
Nov 30 '18 at 9:49





Thanks for the answer!! A little long explanation with more code will be helpful anyway I will go through the link you provided and check if it help.

– Queendevelopers
Nov 30 '18 at 9:49


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405893%2fupdate-single-item-goolgemap-cluster%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks