Tuesday, 7 June 2016

How can Display single user on Map In Java




Step 1-Call function where you put database code

 <%
   int id=Integer.parseInt(request.getParameter("mapId"));
 
   UserBusinessService us=new UserBusinessService();
        User u=us.getuserlatlong(id); %>

Here User is javabean class where getter setter is defined, and UserBusinessService class is that where put database code, i just create the object and call method.

here i use int id, because for going to map you will click on button and for particular user you will have to take userid on button right? :)


Step 2- all google map code will be within javascript

Javascript code is here

   <script language="javascript">
 
   function initialize()
   {

  var lang=<%=u.getLongitude()%>
  var lat=<%=u.getLatitude()%>

  var myCenter=new google.maps.LatLng(lat,lang);

   var mapProp = {
     center:myCenter,
     zoom:12,
     mapTypeId:google.maps.MapTypeId.HYBRID
     };

   var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

   var marker=new google.maps.Marker({
     position:myCenter,

     animation:google.maps.Animation.BOUNCE
     });

   marker.setMap(map);
   }

   google.maps.event.addDomListener(window, 'load', initialize);
   </script>


Here see
  var lang=<%=u.getLongitude()%>
 var lat=<%=u.getLatitude()%>

Its simple getter setter value, i think you know how to take data from database, if dont  know then let me know

Now if you want to change icon color, by default is is red but want to change the use following code

 var pinImage = new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/009900/");

 var marker = new google.maps.Marker({
            position: yourlatlong,
            icon: pinImage,
            map: map
        });

for more details please go here

http://www.googlemapsmarkers.com/


if any query then let me know

Thanks
Keep Happy Learning... :)

No comments:

Post a Comment