Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display location on Google Map in JSP in JAVA?

    • 0
    • 3
    • 1
    • 4
    • 0
    • 0
    • 0
    • 0
    • 10.0k
    Comment on it

    Sometimes we need to display Google Map on a JSP page, for this you just need pass lat/long to JSP. Use below code to initialize map in script:

    var marker = null;
             var map = null;
             var markers = [];
             function initializeMap()
            {
                var map_canvas = document.getElementById('map_canvas');
                var map_options = {
                    //center: myCenter,
                    zoom: 15,
                    mapTypeId: google.maps.MapTypeId.SATELLITE
                }
                map = new google.maps.Map(map_canvas, map_options)
    
            }
    

    And use below code to update required location:

    function updateMap(gps)
        {
            var latitude = "${recentLocation.latitude}";
            var longitude = "${recentLocation.logitude}";
            var gpsPoint = new google.maps.LatLng(latitude, longitude);
            if(marker != null)
                marker.setMap(null);
            if(map!=null)
                map.setCenter(gpsPoint);
            marker = new google.maps.Marker({
            position:gpsPoint,
            map:map
            });
            markers.push(marker);
        }
    

    Define div in which you want to display Google Map:

    <div id="map_canvas"></div>
    

    This will display your location on the map.

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: