Google Maps with Mysql in the Java EE Infrastructure

I am working on a web application with Java EE that takes the address of people from the MySql database and shows their location on Google maps.

I am currently doing this manually, because I don’t know how to integrate Google maps into JSP. Please give me some direction to do this with Java.

+4
source share
3 answers

First, select the list of all addresses from the database, and then using the Google geocoding service, select the latitude for the longitude of these addresses. Here is a sample code ( http://code.google.com/p/gmaps-samples/source/browse/trunk/geocoder/java/GeocodingSample.java?r=2476 ). You can then create a Google map marker on the map. Here is a sample code http://www.paulwest.co.uk/article.php/using-google-maps-api-to-mark-your-location-and-address

Hope this helps.

+1
source

First, you must use the servlet. This servlet retrieves data from the database and converts it to json format.

And using ajax, the json data is taken, and then the Google map JavaScript API is used.

0
source

Hey guys, this code helped the finale, he is very happy, thank you very much.

<sql:setDataSource var="enterdata" driver="com.mysql.jdbc.Driver" user="root" password="root" url="jdbc:mysql://localhost/enterdata" /> <sql:query var="list" dataSource="${enterdata}" sql= "SELECT * from cropdata where FarmerName=\"${param.FarmerName}\"" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false"></script> <script type="text/javascript"> var markers = [<c:forEach var="s" items="${list.rows}"> ['Farmer Name :${s.FarmerName}<br>Crop Type:${s.CropName}',${s.Latitude},${s.longitude}], </c:forEach> ]; function initializeMaps() { var latlng = new google.maps.LatLng(markers[0][1],markers[0][2]); var myOptions = { zoom: 18, center: latlng, mapTypeId: google.maps.MapTypeId.SATELLITE, mapTypeControl: false }; var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); var infowindow = new google.maps.InfoWindow(), marker, i; for (i = 0; i < markers.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(markers[i][1], markers[i][2]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(markers[i][0]); infowindow.open(map, marker); } })(marker, i)); } } 
0
source

All Articles