Thursday, July 19, 2012

How to use Google map api tutorials with examples

Google map api tutorials with examples:

        Google map API is used  for several applications like marking a place on google map , making a path between two places,finding the directions  between two plces and many. Here i am explaining two examples.



                         To work with Google map API we need to have the API key. We can get this key by registering the following website.

Step 1: Register in the below website to get the API key.

https://developers.google.com/maps/documentation/javascript/tutorial#api_key

Note: If you go through the above website, it will give several instructions for getting API key. Follow those instructions.

Step 2: Copy the below code into a notepad and save with Any_Name.html. But use your Google map  API Key in place of  "USE_YOUR_KEY".

Example Code1 to Make a Mark on a Particular Place:

<!---------Add a Marker To Google Map--------------->

<!DOCTYPE html>
<html> 
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />


<style type="text/css">

html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#display_here { height: 100% }

</style>

<script type="text/javascript"      src="

http://maps.googleapis.com/maps/api/js?key=USE_YOUR_KEY&sensor=false"></script>   


<script type="text/javascript">
      var map;
function initialize() {


    var latlng = new google.maps.LatLng(17.3667, 78.4667);
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP

    };

    map = new google.maps.Map(document.getElementById("display_here"), myOptions);

    var marker = new google.maps.Marker
    (
        {
            position: new google.maps.LatLng(17.3667, 78.4667),
            map: map,
            title: 'Click me'
        }
    );
    var infowindow = new google.maps.InfoWindow({
        content: 'Location info:<br/>Country Name:<br/>LatLng:'
    });
    google.maps.event.addListener(marker, 'click', function () {
        // Calling the open method of the infoWindow
        infowindow.open(map, marker);
    });
}

</script> 
</head>
 
<body onload="initialize()">
<div id="display_here" style="width:100%; height:100%"></div>
</body>


</html>



Output: If you run that html, you will see the following output. (You should have good internet connection)




Explanation:

In the above example, google.maps.LatLng(latitude,longitude) will take latitude and longitude of a place as parameters. Zoom property can be used to increase or decrease the size of the google map image. The google.maps.Map() method will take two parameters HTML ID and Options. Here HTML ID tells where to display google map image. The google.maps.Marker() can be used to mark a place on the google map. Here we can set the position of the marker and title. The google.maps.event.addListener() method can be used to add events to a marker.


 Example Code2 to Make a Path Between Two Places:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />


<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#display_here { height: 100% }
</style>

<script type="text/javascript" src="
http://maps.googleapis.com/maps/api/js?key=USE_YOUR_KEY&sensor=false"></script>   
<script>
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;

  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var hyderabad = new google.maps.LatLng(17.3667, 78.4667);
    var mapOptions = {
      zoom:14,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: hyderabad
    }
    map = new google.maps.Map(document.getElementById("display_here"), mapOptions);
    directionsDisplay.setMap(map);
  }

  function calcRoute() {
    var start = document.getElementById("start").value;
    var end = document.getElementById("end").value;
    var request = {
        origin:start,
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }
</script>


</head>

<body onload="initialize()">
<div>
<b>Origin: </b>
<select id="start" onchange="calcRoute();">
  <option value="hyderabad, in">hyderabad</option>
  <option value="pune, in">pune</option>
  <option value="chennai, in">chennai</option>
  <option value="delhi,in">delhi</option>
  <option value="goa">goa</option>
</select>

<b>Destination: </b>
<select id="end" onchange="calcRoute();">
  <option value="bangalore, in">bangalore</option>
  <option value="mumbai, in">mumbai</option>
  <option value="calcutta, in">calcutta</option>
    <option value="vizag">vizag</option>
</select>
</div>
<div id="display_here" style="top:30px;"></div>
</body>
</html>

 Output: If you run that html, you will see the following output. (You should have good internet connection)


 Explanation:

       In the above example we need minimum two places to draw a path between them. Here google.maps.DirectionsService().route() will take care of creating path between two places.

Note: use your Google map API Key in place of "USE_YOUR_KEY".

How to Debug nhibernate.hql.ast.antlr.querysyntaxexception?

How to Debug nhibernate.hql.ast.antlr.querysyntaxexception:

    This error may occur, when we have syntactical errors in the query when working with HQL. The following example explains how to resolve this issue.

You may get error, if you write as below:

select * from Employee;

(or)

select e.* from Employee e;

(or)

select from Employee;


Correct Syntax:

select e from Employee e;

Monday, July 16, 2012

How To Stop Receiving Airtel Flash Messages?

How To Stop Receiving Airtel Flash Messages:

   I recently bought an Airtel sim. I am getting flash messages on the screen continuously. To stop this, We  can do the following steps.

Solution:

Step1: Go to Airtel Live!

Step2: Click on Airtel Now

Step3: Click on Start/Stop

Step4: Click on Stop

Thursday, July 12, 2012

Difference between string and stringbuffer in java with example?

Difference between string and stringbuffer in java with example:

   The main difference between String and StringBuffer is, String objects are immutable and StringBuffer objects are mutable. Here Immutable means we can not change the contents of an object. Consider the following example.

Example for String Immutable:

String name1="Hello";   //Hello will be stored in name1

String name2="World";    //World will be stored in name2

name1=name1+name2; //Trying to add something to Hello

System.out.println(name1);

Output:

HelloWorld

             In the above example we said that String objects are immutable, but the content of name1 is changed from Hello to HelloWorld. It is little surprising right?,Here the reason is when we are trying to add two strings a new object is created. Here the new object is HelloWorld. In place of Hello the HelloWorld will be replaced. This will be done internally. We can not notice that.

Example for StringBuffer mutable:

StringBuffer name1=new StringBuffer("Hello"); //Hello will be stored in name1
StringBuffer name2=name1; // We are assigning Hello to name2 also
 name2.append("World"); // We are adding an World to Hello
System.out.println(name1);
System.out.println(name2);


Output:

HelloWorld
HelloWorld

                   In the above example we  are trying to change the contents of name2. Here we are adding World to name2.  When displaying name1, it should print Hello and when displaying name2 it should print HelloWorld. But Cleary Observe, In the above example both name1 and name2 are printing HelloWorld only. Here the reason is, both name1 and name2 are sharing the same object. When we change the content of an object, the same object will be changed. Here new object will not be created.

Nunit can not load file or badimage error?

            This error may occur if we dont have a proper configuration of a project. So right click on the project and select properties, then properties window will be opened as follows.Then click on build you will see the window like this.


Note: Change the Platform target to Any CPU. Your problem will be solved

How to Use Time in C# With Example?

Working With Time in C# Example:

We can use TimeSpan Class to work with time in C#. By using this class we can add two times,we can subtract two times. We can format the time according to hours,minutes,seconds and milliseconds.

Example:
class TimeExample
{
static void Main(string[] args)
{
          /*----------Working With Tim e--------------------*/
TimeSpan time1 = new TimeSpan(1,1,30,30); //Parameters are days,hours,mins,secs
Console.WriteLine("Time With Our Values: "+time1);
TimeSpan time2 = new TimeSpan(1, 30, 30); //Parameters are hours,mins,secs
Console.WriteLine("Time With Our Values: " + time2);
           /*-----------Add Two Times----------------*/
TimeSpan span1 =new TimeSpan(2,3,20); //It is 02:03:20 hr:min:sec
TimeSpan span2 = new TimeSpan(5, 3, 20); //It is 05:03:20 hr:min:sec
TimeSpan span3 = span1.Add(span2); //It is 07:06:40
Console.WriteLine("After Adding two Times: "+span3);
}
}

Output:

How to Use Date and Time in C# With Example?

Working With Date in C# Example:

 We can use DateTime Class in C# to work with date and time. From that we can get today's date. If we want yesterday's date we can add -1 to current date. If we want tomorrow's date we can simply add 1 to the current date. The following example illustrates how to work with date and time in c#.

Example Code:
  
class DateAndTimeExample
{
static void Main(string[] args)
{
   /*----------Working With Date--------------------*/
       
DateTime value = new DateTime(2012,2, 25);
Console.WriteLine("Date With Our Values:"+value); //It will print date with our values
Console.WriteLine("Today's Date:" + DateTime.Today);
Console.WriteLine("Tomorrow Date:" + DateTime.Today.AddDays(1));
Console.WriteLine("Yesterday Date:" + DateTime.Today.AddDays(-1));
}
}
Output: