-
Notifications
You must be signed in to change notification settings - Fork 916
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
Bug: marker locates when map.addMarker({ visible: false }) #153
Comments
In general programming, your algorithm is not better way. And PhoneGap / Cordova execute each commands as pipeline. The better way I think is:
For example using async.js: function onPageLoaded(map) {
var dummy = [];
for (var i = 0; i < 50; i++)
dummy.push(i);
async.map(dummy, function(i, callback) {
map.addMarker({
visible: false
}, function(marker) {
//Listen the photo_change event
map.on("photo_change_" + i, function(photo) {
var position = new plugin.google.maps.LatLng(photo.latitude, photo.longitude);
marker.setPosition(position);
marker.setVisible(true);
marker.set("photo_url", photo.photo_file_url);
});
//Bind the same event listener for all markers
marker.on(plugin.google.maps.event.MARKER_CLICK, function() {
openPhoto(map, marker.get("photo_url"));
});
callback(null, marker);
});
}, function(markers) {
setInterval(function() {
map.getVisibleRegion(function(latLngBounds) {
// Get 50 photos from Panoramio
$.ajax({
url: "http://www.panoramio.com/map/get_panoramas.php",
type: "GET",
dataType: "jsonp",
async: true,
data: {
"order": "popularity",
"set": "public",
"from": 0,
"to": 50,
"maxx": latLngBounds.northeast.lng,
"maxy": latLngBounds.northeast.lat,
"minx": latLngBounds.southwest.lng,
"miny": latLngBounds.southwest.lat
},
success: function(json){
var photos = json.photos;
if (!photos) {
return;
}
photos.forEach(function(photo, i) {
map.trigger("photo_change_" + i, photo);
});
}
});
});
}, 10000);
});
}
function openPhoto(map, photo_url) {
var photoDiv = $("<div>").css({
"position": "fixed",
"left": "10%",
"top": "10%",
"right": "10%",
"bottom": "10%",
"z-index": 1001,
"background-image": "url('" + photo_url + "')",
"background-size": "cover",
"background-position": "center"
});
photoDiv.appendTo("body");
var backGround = $("<div>").css({
opacity: 0.7,
backgroundColor: "black",
"position": "fixed",
"left": 0,
"top": 0,
"right": 0,
"bottom": 0,
"z-index": 1000
});
backGround.one("click", function() {
$(backGround).remove();
$(photoDiv).remove();
map.setVisible(true);
});
backGround.appendTo("body");
map.setVisible(false);
} |
Thanks for your answer! I know this is not good algorithm, it was just for running a test on markers. I just wanted to be sure that adding then removing markers was not memory consuming.
|
How many shops totally do you have? Prepare the point plotted images, then load them based on the area. map.on(plugin.google.maps.event.MAP_CLICK, function(click_latLng) {
var hitShop = shops.filter(function(shop) {
if (shop.latlngBounds.contain(click_latLng)) {
return true;
}
return false;
});
}); |
Thank you. In fact I have a very large number of point (>100k) so I have a server script that send only those in the user proximity. I implemented you idea of initializing an array of invisible markers. |
Thank you for letting me know. I will fix it in next release. |
Hey I have a program running with cordova. Every 10 seconds I receive a list of 50 locations that I plot using markers.
Each time I receive a new list I remove the former markers with marker.remove() and then plot the new ones.
But my program gets slower and slower. After 1~2 minutes it is not responding at all. Is that normal? isn't suppose marker.remove() clear the memory ?
How can I handle this ?
The text was updated successfully, but these errors were encountered: