Saturday, 15 June 2013

javascript - 'Uncaught InvalidValueError: setContent: not a string; and [object Console]' error in Google Map -



javascript - 'Uncaught InvalidValueError: setContent: not a string; and [object Console]' error in Google Map -

i have follow page displaying google map using google maps api

class="snippet-code-html lang-html prettyprint-override"><!doctype html> <html> <head> <style type="text/css"> #map{ width:400px; height:400px; border:2px solid black; margin-top:20px; } </style> </head> <body> <div id="location"> <p>your location displayed here</p> </div> <div id="map"></div> <script> var map; var div = document.getelementbyid("location"); window.onload = getmylocation; function getmylocation(){ if(navigator.geolocation){ navigator.geolocation.getcurrentposition(displaylocation,displayerror); }else{ alert("sorry, browser not back upwards geolocation"); } } function displaylocation(position){ var latitude = position.coords.latitude; var longitude = position.coords.longitude; div.innerhtml = "you @ latitude: "+latitude+", longitude: "+longitude; showmap(position.coords); } function displayerror(error){ if(error.code==0){ div.innerhtml="an unknown error occurred."; }else if(error.code==1){ div.innerhtml="you denied request geolocation."; }else if(error.code==2){ div.innerhtml="location info unavailable."; }else if(error.code==3){ div.innerhtml="the request user location timed out."; } } function showmap(coords){ var googlelatandlong = new google.maps.latlng(coords.latitude,coords.longitude); var mapoptions = { zoom:10, center:googlelatandlong, maptypeid:google.maps.maptypeid.roadmap }; var mapdiv=document.getelementbyid("map"); map = new google.maps.map(mapdiv,mapoptions); var title="your location"; var content = "you here: "+coords.latitude+", "+coords.longitude; addmarker(map,googlelatandlong,title,console); } function addmarker(map,latlong,title,content){ var markeroptions = { position:latlong, map:map, title:title, clickable:true }; var marker = new google.maps.marker(markeroptions); var infowindowoptions = { content:content, position:latlong }; var infowindow = new google.maps.infowindow(infowindowoptions); google.maps.event.addlistener(marker,"click",function(){ infowindow.open(map); }); } </script> <script src="https://maps.google.com/maps/api/js?sensor=true"></script> </body> </html>

note: code snippet might not work because blocking request of geolocation api.

when load page, map displays correctly marker, when click on marker nil happens (it's supposed display window) , js console throws next error

uncaught invalidvalueerror: setcontent: not string; , [object console]

i read similar posts , seems issue whatever value content has, it's not string. content variable declared here

class="snippet-code-html lang-html prettyprint-override">var content = "you here: "+coords.latitude+", "+coords.longitude; addmarker(map,googlelatandlong,title,console); } function addmarker(map,latlong,title,content){ var markeroptions = { position:latlong, map:map, title:title, clickable:true }; var marker = new google.maps.marker(markeroptions); var infowindowoptions = { content:content,

i tried converting coords.latitude , coords.longitude strings (not in version of code) , didn't create difference.

any ideas on causing this? code comes head first html5 programming , don't mention issue @ all.

it syntax error

i had

addmarker(map,googlelatandlong,title,console);

should be

addmarker(map,googlelatandlong,title,content);

not sure got 'console' from.

javascript html5 google-maps google-maps-markers

No comments:

Post a Comment