Friday, 4 January 2013

"Geolocation Tracing && Mobile browser detection"



How to get the latitude and longitude of current geo position using HTML5 in mobile web and PC web (Map view)  ?? 

This is one of the task in my recent completed project. The following code works very nice in detecting current location in all types of mobile web and pc web. This snippet may help you . . . ! 

       *Concentrate on geolocation tracing and mobile browser detection functionality.
          -------------------------------------------------------------------------------------------
<!DOCTYPE:html>
<html>
<head>
                <title>Geolocation Example</title>
                <meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
</head>
<body>
                 <div id="map"></div>  
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
detectBrowser();
initGoogleMap();
getLocation();

// Detect support and request the current location.
function getLocation()
{
                if ( navigator.geolocation )
                {
                                navigator.geolocation.getCurrentPosition(handlePosition, handleError);
                }
                else
                {
                                alert("Sorry, geolocation is not supported.");
                }
}

// Receives a successful geolocation response.
function handlePosition(pos)
{
                // Center the map on the current location
                latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
                map.setCenter(latlng);
               
                // Drop a marker on the current location
                marker = new google.maps.Marker
                ({
                                map: map,
                                draggable: false,
                                animation: google.maps.Animation.DROP,
                                position: latlng
                });
}

// Receives and display geolocation request error.
function handleError(error)
{
                switch (error.code)
                {
                                case error.PERMISSION_DENIED:
                                                alert('Permission was denied');
                                                break;
                                case error.POSITION_UNAVAILABLE:    
                                                alert('Position is currently unavailable.');
                                                break;
                                case error.PERMISSION_DENIED_TIMEOUT:
                                                alert('User took to long to grant/deny permission.');
                                                break;
                                case error.UNKNOWN_ERROR:
                                                alert('An unknown error occurred.')
                                                break;
                }
}

// Initialize and display the google map in the element with id "map"
function initGoogleMap()
{
                options =
                {
                                zoom: 10,
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map"), options);
}

// Detect the current browser and display full screen for Android / iPhone
function detectBrowser()
{
                var userAgent = navigator.userAgent;
                var mapDiv = document.getElementById("map");

                if (userAgent.indexOf('iPhone') != -1 || userAgent.indexOf('Android') != -1 )
                {
                                mapDiv.style.width = '100%';
                                mapDiv.style.height = '100%';
                }
                else
                {
                                mapDiv.style.width = '600px';
                                mapDiv.style.height = '800px';
                }
}

</script>
</body>
</html>
              -------------------------------------------------------------------------------------------

Crop an image when selected from gallery in android


                     I'm facing a problem with parsing a Uri of taken photo to crop activity. In my application, users can take a photo or select one from gallery and then crop it and upload it. Here I can’t crop whole image.
I use the below code:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setData(uri);
intent.putExtra("outputX", 96);
intent.putExtra("outputY", 96);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);            
startActivityForResult(intent, REQUEST_CODE_CROP);

             Now I got the solution to this crop functionality for take picture or from gallery. Following code I used its working if any other way is their please let me know.:


case REQ_CODE_PICK_IMAGE:
if (resultCode == RESULT_OK) {
  send.setVisibility(View.VISIBLE);
//             Display();
 gallery.setVisibility(View.INVISIBLE);                               
 img_gallery.setVisibility(View.INVISIBLE);
           if (imageReturnedIntent != null)
                               {
           File tempFile = getTempFile();
            String filePath = Environment.getExternalStorageDirectory()+ "/temporary_holder.jpg";
           System.out.println("path " + filePath);
           Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
           ImageView imageView = (ImageView) findViewById(R.id.bakgnd);
           int imgHeight = selectedImage.getHeight();
          int imgWidth = selectedImage.getWidth();
          int containerHeight = imageView.getHeight();
           int containerWidth = imageView.getWidth();
          boolean ch2cw = containerHeight > containerWidth;
         float h2w = (float) imgHeight / (float) imgWidth;
          float newContainerHeight, newContainerWidth;
         if (h2w > 1) {
        if (ch2cw) {
                           newContainerWidth = (float) containerWidth;
                           newContainerHeight = newContainerWidth * h2w;
                                 }
                     else {
                                   newContainerHeight = (float) containerHeight;
                                   newContainerWidth = newContainerHeight / h2w;
                              }
                        } 
                  else {
                        if (ch2cw) {
                              newContainerWidth = (float) containerWidth;
                               newContainerHeight = newContainerWidth / h2w;
             } else {
                           newContainerWidth = (float) containerHeight;
                           newContainerHeight = newContainerWidth * h2w;
                             }
                       }
            image = Bitmap.createScaledBitmap(selectedImage,
            (int) newContainerWidth, (int) newContainerHeight,
                           false);
             imageView.setBackgroundDrawable(new BitmapDrawable(image));
                     //                             img.setBackgroundDrawable(null);
            }

Time Out Error in Eclipse



Where: This will be occurs like " adb connection time out " when you want launching the application. We can fix this error by following steps.



 How to fix:
->Go to window menu in the eclipse .
->Under select preferences .
->Then select android--
 ->Select DDMS 
 ->left side we have adb connection time out (ms)here we need to increases the time out value.




 Hope help full .
I am facing the problem with,
     When i started the Tomcat through Eclipse,by default 8080 port number is allocated to some another services,that's way i am changing the port number of the eclipse.Once i closed the eclipse the changed port number is still working continuously the the server is not working properly.

The solution is
         1. First of all check what are the services running on the system through command prompt

                 netstat -nao this command gives the following resut like
                    Proto  Local Address          Foreign Address        State           PID
                    TCP    0.0.0.0:8080             0.0.0.0:0              LISTENING       4352
                    TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       828

                    Here you found the PID number for each port number (like 8080 port),the open the Tsak Manager tab the services then you find the PID, based on this PID you can find which services are using  what port then you can stop the service.   (OR)
                  If the port number was changed next time if that port is still running on the PID is 0 or some another invalid PID, the solution for this is killing the service through the command prompt like,

                 taskkill /PID 8080 /F
Here we /F means we are killing the service forcibly.