Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I have create a map in shows that marker in location of latitude & longitude but I have issue in getting a values in location.

var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);

HTML
geomfeatures=document.getElementById("featurebox");
                         //alert(geomfeatures.childNodes.length);
                         for(i=0;i<geomfeatures.childNodes.length;i++)
                         {
                             lat=document.getElementById("lat"+i).value;
                             alert(lat);
                             lng=document.getElementById("lng"+i).value;
                             alert(lng);
                             L.marker([lat,lng]).bindPopup("Hello World").addTo(map);

                         } 

<a href="http://localhost:8080/LeafletMarker/"></a>


What I have tried:

HTML
function test()
        {
            geomfeatures=document.getElementById("featurebox");
                  //  alert(geomfeatures.childNodes.length);
                    for (i=0;i&lt;geomfeatures.childNodes.length;i++)
                    {
                        totalgeom=document.getElementById("geom"+i).value;
                        alert(totalgeom);
                    }
        }
        
    
  
        <%
        response.setHeader("Cache-Control", "no-cache"); //Forces caches to obtain a new copy of the page from the origin server
        response.setHeader("Cache-Control", "no-store"); //Directs caches not to store the page under any circumstance
        response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
        response.setHeader("Pragma", "no-cache"); //HTTP 1.0 backward compatibility
        %>
        <jsp:useBean id="Join" class="beans.LeafletJoin"/>
                <% 
                    ArrayList<hashmap> temp = null;
                    temp = Join.getGeometryList();
                    request.setAttribute("geom", temp);
                %>  
                
                <div id="featurebox">
                    <c:forEach var="row" items="${geom}" varStatus="status">
                        <input type='hidden' id="lat<c:out value="${status.index}"/>" value="<c:out value="${row.latitude}"/>"/>
                        <input type='hidden' id="lng<c:out value="${status.index}"/>" value="<c:out value="${row.longitude}"/>"/>
                    
                </div>  
              
                <div id="map"></div>
Posted
Updated 28-Dec-16 8:27am
v2
Comments
Suvendu Shekhar Giri 22-Dec-16 1:36am    
Where exactly you are getting the error?
Member 12917048 3-Jan-17 1:40am    
lat=document.getElementById("lat"+i).value;

can not read value in this lat & longitude how to solve it

1 solution

The error says you are trying to access an object that is actually null. You need to fix that. Since you did not tell us which line of code is causing the error we cannot tell you more than that.
 
Share this answer
 
Comments
Member 12917048 3-Jan-17 1:36am    
lat=document.getElementById("lat"+i).value; this line of code is error
ZurdoDev 4-Jan-17 15:59pm    
OK, so that means that when the code runs document.getElementById("lat"+i) is null. The object does not exist. You'll have to debug it to see what value i has and then figure out why it is not working the way you want it to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900