1

I have a CartoDB question.

We have a project we are piloting in Rio das Pedras, Brazil, a favela near Rio.

We have sampling points, working on adding Fulcrum photo uploads and some pretty bad road linework from a university there, but the labels are helpful for our field team. http://beh-gis.github.io/maps/rdp_loc.html

For this map, I’m trying to add a GPS dot, that shows where the user is. I grabbed some code from a CartoDB example (http://docs.cartodb.com/tutorials/query_by_distance.html) and it asks the user to use location but seems to Error out or something.

Here’s the html code: https://github.com/beh-gis/beh-gis.github.com/blob/master/maps/rdp_loc.html

closed as off-topic by PolyGeo Nov 25 '18 at 11:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

2

The map variable you're referring to doesn't exist in the scope where you're attempting to use it. There are a few ways to handle this, but with a relatively small page like this I would just make sure you define the variable outside of any function ("globally"). Eg:

<script> // credit: http://html5doctor.com/finding-your-position-with-geolocation/
var map;  // This is the bit I added.
function detectUserLocation(){
    ...

Then when you set the variable later, don't use var again (that would redefine it). So instead of

var map = vis.getNativeMap();

use

map = vis.getNativeMap();

Finally, if you plan on using JavaScript more I'd recommend getting acquainted with the Developer Tools for your browser of choice. They should help you get a better idea of why your pages don't work the way you expect them to. And I'd recommend using a service like jsbin to post code so others can quickly see it in use and try it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.