ChadKillingsworth/geolocation-marker

Example code works only once in desktop Chrome. Other browsers works great.

Closed this issue · 6 comments

Hey Chad,

Sorry to keep bugging you but since you are responding I thought I would ask you one last question. The new code you linked to works great in ios Safari, ios Chrome, desktop Firefox. It does work in Desktop Chrome the first time I execute it. However, it does not work if I run the code a second time(I only get a zoomed up map of Australia), unless I refresh the page or switch to another chrome tab and then back. Very bizarre.

The chrome location sharing is set to ALWAYS.

This seems more like a chrome bug then yours (mine?) but I can't explain the behavior. Can you?

Thanks again.

You will have to post a link to a live web site where I can recreate the issue. I haven't seen this behavior myself.

I played with it some more today and still could not get it to work properly in Chrome. IE, Firefox, ios safari, ios chrome all work fine.

I'm working on a jquery mobile project and set up a test button for you on the main page. You can't miss it :)

Click on the button the first time and your geo location shows up. Press back button and try again and the code then fails only in chrome. If you refresh the main page it will work again at least for the first step. It appears that the below listener never gets called the second time in Chrome.

google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {

I hope it's an easy fix :)

Here is the website:
redacted :)

Here is the code that is executed by clicking the button. It is at the top of the 'project.js' file if you would like to step thru it. I stripped it out to it's bare essentials.

$(document).on("pageshow", "#page_test", function () {

var mapOptions = {
  zoom: 12,
  center: new google.maps.LatLng(-34.397, 150.644),
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById('map_canvas'),
    mapOptions);

var GeoMarker = new GeolocationMarker();

GeoMarker.setCircleOptions({fillColor: '#808080'});

google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
  map.setCenter(this.getPosition());
  map.fitBounds(this.getBounds());
});

GeoMarker.setMap(map);
});

Chrome is apparently rate limiting how often it will give position updates. You can work around this by allowing cached values - for instance you could tell chrome that any valid position within the last 60 seconds is ok. This is set through the setPositionOptions method. See the link to the options and description in the documentation.

It's definitely a chrome issue - has nothing to do with this library. You may want to ask on stackoverflow if you have additional problems.

Thanks for looking at it. :)

It does immediately work if you click on another chrome tab and then back to the map page. It seems that would have nothing to do with rate limiting but what do I know :) It's still a Chrome issue. If you are still curious I will put back the test button for you to see for yourself. Again. Thanks for your help.

I noticed the behavior with with losing then regaining focus. I was able to add event listeners and see the issue in your code. Rate limiting is not quite the correct term. My best guess is that when you add a callback to the watchPosition method, multiple callbacks all get updates at the same time a later ones don't necessarily get an immediate update.