skill paper

  • paper

Saturday, August 27, 2011

Map for Beginners

Sample map:
       Create new project,(file->new->androis project).
     Add permission to access internet in manifestXml.
    
    
    

   Next edit main.xml:
             
  ?xml version="1.0" encoding="utf-8"?>  
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
com.google.android.maps.MapView>

      android:id="@+id/mapview"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:clickable="true"
    android:apiKey="Your Maps API Key" />


Iam Sure your u have Api key...

    1. public class HelloMapView extends MapActivity {}
                                           - extend mapActivity instead od Activity .
     2. protected boolean isRouteDisplayed()
{
   
return false;//override this into false
}


      3.initialize below in oncreate()
     mapView = (MapView) findViewById(R.id.mapview);
     mapView
.setBuiltInZoomControls(true);


NOW RUN IT....
you seem to get like this

Generally Map Load from USA and BRASIL.you can change the to your location....
for your query post me here,

gps-map



Creating a Custom Layout as a Transparent Panel


We wanted our transparent panel to hold children so we looked for the most natural Android view to extend and selected Linear Layout because we wanted our TransparentPanel class to layout its children horizontally. We could just as easily chosen to extend RelativeLayout of any other layout class.

       1.TransparentPanel extends LinearLayout


The ‘magic’ of TransparentPanel happens in the dispathDraw() method. For those of you that have already created their own custom Views, you might wonder why we override dispatchDraw() instead of onDraw(). For some reason, LinearLayout does not call it’s own onDraw() method…apparently because its developer assumes a LinearLayout would never have anything to draw. BUT we want our TransparentPanel to draw a background so we override dispatchDraw() to draw the background and then let super.dispatchDraw(canvas) render any child components.


    
          protected void dispatchDraw(Canvas canvas) {
 
	           RectF drawRect = new RectF();
	           drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
 
	           canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
	           canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
 
	           super.dispatchDraw(canvas);
                }


For those new to drawing their own graphics, let’s review a few items here. First, we populate a RectF with the coordinates of the background that we want to draw. Next we make to calls to drawRoundRect(). The 1st call passes innerPaint to draw the transparent gray background while the 2nd call passes the white border that we want to paint. Lastly we call super.dispatchDraw(canvas) to render our child components (in this case a Button).







The gray background is rendered with an alpha (transparency ) == 225. This allows just enough of the map to show through.





                                      1 innerPaint.setARGB(225, 75, 75, 75);


And borderPaint allows us to render a white border with a Stroke of width = 2.



                   borderPaint = new Paint();
                   borderPaint.setARGB(255, 255, 255, 255);
                   borderPaint.setAntiAlias(true);
                   borderPaint.setStyle(Style.STROKE);
                   borderPaint.setStrokeWidth(2);
 
 
As we did above, make sure to setAntiAlias(true) so the borders of your paint blend seamlessly with its surroundings. Set this option to false to see how your borders would have jagged edges otherwise.


Adding our custom TransparentPanel class as a declarations in the layout XML.


Now we’re ready to insert the TransparentPanel into our layout XML class and to add a button. To reference our new class, we simply provide the full classpath to our the TransparentPanel and then provide layout parameters as we would for any LinearLayout. In this case, we provide padding so our Button does not rest against the edges of our TransparentPanel’s border.




xml layout: