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)