markermanager stopped working - no errors - google-maps-api-3

Couple days ago markermanager stopped working properly with google maps. I have no error in console view.
It's breaking on line:
var div = this.getProjection().fromLatLngToDivPixel(latlng)
this is whole method:
ProjectionHelperOverlay.prototype.LatLngToPixel = function (latlng, zoom) {
alert('p1');//displays alert
var map = this._map;//object
alert('p2');//displays alert
alert(latlng);//displays object
var div = this.getProjection().fromLatLngToDivPixel(latlng);
alert('p3');//NO ALERT and NO error in console
var abs = {x: ~~(0.5 + this.LngToX_(latlng.lng()) * (2 << (zoom + 6))), y: ~~(0.5 + this.LatToY_(latlng.lat()) * (2 << (zoom + 6)))};
alert('p4');//never gets to that line
return abs;
};
Everything was fine before and I didn't make any changes.
Could it be error with new google maps API code?
I can't find newer version of markermanager.
Is there any replacement for this script?

Are you either using the nightly/experimental version (v3.exp), v3 or an old version?
Versioning
If so the version of the maps API could have changed underneath your page. The Google Maps API team recommends you hardcode the version number on production pages and test newer versions before going live with them.

I was having the same error, adding a listener to the loaded event did it for me:
var mgr = new MarkerManager(map)
google.maps.event.addListener(mgr, 'loaded', function(){
mgr.addMarkers(markers, 5,6)
});

Related

Unable to download ERA5 land hourly data via Google earth engine platform recently

Recently I find that I can't download ERA5 land hourly data via Google Earth Engine, and the following code can only return null. But if I replace the first row with "var era51 = ee.ImageCollection('ECMWF/ERA5/DAILY')", it could return the images. Is there something wrong with the ERA5 land hourly data?
Here is the code:
var era51 = ee.ImageCollection("ECMWF/ERA5_LAND/HOURLY")
.filterDate('2018-01-01', '2018-02-02')
.select('total_precipitation');
function exportImageCollection(imgCol) {
var indexList = imgCol.reduceColumns(ee.Reducer.toList(), ["system:index"])
.get("list");
indexList.evaluate(function(indexs) {
for (var i=0; i<indexs.length; i++) {
var image = imgCol.filter(ee.Filter.eq("system:index", indexs[i])).first();
print(image)
}
});
}
exportImageCollection(era51);
EDIT: Turns out that it was a problem on the Dataset side. It is now fixed. Happy downloading :)
Same problem here, about last week my script worked smoothly, but today it just fails. I use to work with the python API, but I've been able to download Landsat-[5,8] images with no problem.
I tried to use Earth Engine Javascript API to download the same area with both: an URL (image.GetDownloadURL()) and to Drive (Export.image.toDrive()); but both approaches also failed.
Tests in Javascript API:
var imgcol = ee.ImageCollection("ECMWF/ERA5_LAND/HOURLY");
var subset = imgcol.filterDate("2010-09-11T10", "2010-09-11T11").filterBounds(geometry);
var img = subset.map(function(x){return x.clip(geometry);}).first();
Map.addLayer(subset.select("surface_latent_heat_flux"))
var url = img.getDownloadURL(
{
name: 'single_band',
bands: ['surface_latent_heat_flux'],
region: geometry
}
);
print(url); //url is printed but fails in the download
Export.image.toDrive(
{
image: img,
description: 'LET',
folder: 'ee_test',
region: geometry,
scale: 9000
});
Could it be an error in Earth Engine end?
EDIT: Turns out that it was a problem on the Dataset side. It is now fixed. Happy downloading :)

Google Maps API In Apps Script Keeps Failing

I'm using google apps script to code a distance finder for Google Maps. I've found examples of such, but they keep failing, so I thought I'd code my own. Sadly, this is failing with the same error:
TypeError: Cannot read property "legs" from undefined. (line 16).
It seems to be that it's sometimes working, and sometimes not. I have a few (3) places in my sheet that are calling the same functions, and at times one or more will return a valid response.
I saw elsewhere that people were suggesting using an API key to make sure that you get a good response, so that's what I've implemented below. (api keys redacted! is there a good way to tell if they've been recognised?)
Any ideas what might be going awry?!
Thanks in advance,
Mike
function mikeDistance(start, end){
start = "CV4 8DJ";
end = "cv4 9FE";
var maps = Maps;
maps.setAuthentication("#####", "#####");
var dirFind = maps.newDirectionFinder();
dirFind.setOrigin(start);
dirFind.setDestination(end);
var directions = dirFind.getDirections();
var rawDistance = directions["routes"][0]["legs"][0]["distance"]["value"];
var distance = rawDistance/1609.34;
return distance;
}
Here's my short term solution while the issue is being fixed.
Not ideal, but at least reduces using your API limit as much as possible.
function getDistance(start, end) {
return hackyHack(start, end, 0);
}
function hackyHack(start, end, level) {
if (level > 5) {
return "Error :(";
}
var directions = Maps.newDirectionFinder()
.setOrigin(start)
.setDestination(end)
.setMode(Maps.DirectionFinder.Mode.DRIVING)
.getDirections();
var route = directions.routes[0];
if (!route) return hackyHack(start, end, level+1); // Hacky McHackHack
var distance = route.legs[0].distance.text;
// var time = route.legs[0].duration.text;
return distance;
}

'item.geometry.location.kb' and 'item.geometry.location.jb' returning undefined

I'm using Google Maps to get an autocomplete list of cities.
I used to use item.geometry.location.kb as the longitude and item.geometry.location.jb as the latitude, but they are not defined since today/yesterday.
Apparently, one has to use item.geometry.location.lng() and .lat() instead.
I didn't know that and I have an app using item.geometry.location.kb and jb in Google Play and the AppĀ Store.
So my apps are not working any more.
Why has a change has been made and how can I revert to kb and jb?
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function(event) {
var item = autocomplete.getPlace();
curLon = item.geometry.location.kb;
curLat = item.geometry.location.jb;
// ...
Don't use undocumented properties of the Google APIs. They can and do change with every release.
geometry.location is a google.maps.LatLng object, and the documented methods to get latitude and longitude are .lat() and .lng().

Meteor multiplayer game clients get out of sync - how to debug?

I've built a simple real-time multiplayer math game in Meteor that you can try out here: http://mathplay.meteor.com
When playing locally (using different browsers), everything works fine. But when I play over the Internet with friends, the clients often get out of sync: a question listed as active for one player is actually already solved by another player.
My guess is that some code that should be server-only gets executed on one of the clients instead. Any suggestions on how to debug this behavior?
Here is what happens on the client when user submits an answer:
Template.number_input.events[okcancel_events('#answertextbox')] = make_okcancel_handler({
ok: function (text, event) {
question = Questions.findOne({ order_number: Session.get("current_question_order_number") });
if (question.answer == document.getElementById('answertextbox').value) {
console.log('True');
Questions.update(question._id, {$set: {text: question.text.substr(0, question.text.length - 1) + question.answer, player: Session.get("player_name")}});
callGetNewQuestion();
}
else {
console.log('False');
}
document.getElementById('answertextbox').value = "";
document.getElementById('answertextbox').focus();
}
});
callGetNewQuestion() triggers this on both client and server:
getNewQuestion: function () {
var nr1 = Math.round(Math.random() * 100);
var nr2 = Math.round(Math.random() * 100);
question_string = nr1 + " + " + nr2 + " = ?";
question_answer = (nr1 + nr2);
current_order_number = Questions.find({}).count() + 1;
current_question_id = Questions.insert({ order_number: current_order_number, text: question_string, answer: question_answer });
return Questions.findOne({_id: current_question_id});//current_question_id;
},
Full source code is here for reference: https://github.com/tomsoderlund/MathPlay
Your problem lies with this:
callGetNewQuestion() triggers this on both client and server
This will generate a different _id because of the timing difference, as well as a different question which will then get replaced with that one that the server generated. However, this might not always be the case. This makes it very easy to let things get out of sync, simply because your client is generating its own stuff.
You'll need to figure out a better approach at making sure the client generates the same data as the server. Which can be done by making sure that a random number generator is seeded the same way and thus would give the same random numbers every time. This will resolve any flickering because the values are different.
Then, for the actual bug you might not want to do this:
return Questions.findOne({_id: current_question_id});
But do this instead (only on the client, do nothing on the server):
Session.set('current_order', current_order_number); // ORDER! Not the _id / question_id.
That way, you can put the following in a template helper:
return Questions.findOne({ order_number: Session.get('current_order') });
In essence, this will work in a reactive way on the Collection and not dependent on the return value.

Google Maps Api v3 - new MarkerClusterer works too slow?

to create map clusterer, i use:
markerClustererGPC = new MarkerClusterer(myMap.map, markersGPC, GPCOptions);
but sometimes it does not works, and markerClustererGPC is sometimes undefined.
i search on this problem, and realise that (it looks like) server is sometimes too fast, and cluster is not defined due to that.
if server is a bit older (slower), it works without problems.
am i right about this? what can i do to avoid this problem, to make my code proper to work on any server?
i think because google map is not loaded completed so your map is unidentified.
Try add this:
var isLoad = false;
google.maps.event.addListener(map,'tilesloaded',
function () {
if (!isLoad) {
isLoad = true;
LoadClusterFunction();
}
});
after your call for creating map (map is variable for google map)

Resources