1

I am trying to get Location of user via javascript Geolocation API, and show a static image of the map using google maps API, but when I tried to run the script in a webpage, it didn't work,In chrome's javascript console, it says "Uncaught SyntaxError: Unexpected identifier". I am a bit confused because, there are no misplaced or extra semicolons. Here's the javascript code :

    var button = document.querySelector("#button");
    var output = document.querySelector("#output");

    window.onload = init;
    function init(){
        button.addEventListener('click',getPosition,false);
    }
    function getPosition(evt){
        var pos = navigator.geolocation.getCurrentPosition(showPosition,onError,{enableHighAccuracy:true,maximamAge:2000});
        console.log(pos);
    }
    function showPosition(position){
        output.innerHTML = "Your Current position is <br/> Latitude : "+position.coords.latitude+" ,  Longitude : "+position.coords.longitude;
        var latlon = position.coords.latitude+","+position.coords.longitude;
        var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&size=400x300&sensor=false";
        document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"' />";
    }
    function onError(){
        output.innerHTML = "Something is wrong with your browser";
    }

When I checked this code on JSLint it says "Unexpected character ';' ". I tried a lot but I am unble to find what's causing the problem. Please help me with that, Any type of suggestions are also welcome.

1
  • the code you posted passes jslint just fine Commented Dec 23, 2015 at 7:55

1 Answer 1

2

Rows 15 and 16 end with wrong encoded semicolons, I replaced them with "normal" ones and it works.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the fiddle with your code: jsfiddle.net/ueon5xme It triggers the error "Uncaught SyntaxError: Unexpected token ILLEGAL", now replace the semicolons at the end of rows 21 and 22 and it will work :D
They seem to be unicode characters "U+037E" corresponding to "greek question mark"...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.