Google Map show after button click

Tutorials that use the MapActivity. Many using GPS functionality.

Google Map show after button click

Postby danishjee » Thu Aug 25, 2011 4:56 pm

hi all,
I AM NEW , i need some help.
I have one main page ,after main page click go to map page

here is my code which is not working properly where i am doing mistake
main.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"   
android:layout_width="wrap_content"
    android:layout_height="wrap_content"
       android:stretchColumns="3"> 
           
         <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
             <Button android:text="Map" android:layout_height="wrap_content" android:padding=" 12px" android:drawableTop="@drawable/map_img" android:textColor="#FFFFFF" android:id="@+id/button1" android:layout_width="wrap_content" android:background="@null"></Button>
          </TableRow>   
                   
           </TableLayout>


map.xml
Code: Select all
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <com.google.android.maps.MapView
            android:id="@+id/mapView"
                 android:layout_width="fill_parent"
                 android:enabled="true"
                 android:clickable="true"
                 android:apiKey="mapidworking"
                 android:layout_height="424dp"/>
</LinearLayout>


myMenu.java
Code: Select all
public class myMenu extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
      
       Button btgic_map =(Button) findViewById(R.id.button1);
       btgic_map.setOnClickListener(new View.OnClickListener() {
         
         @Override
         public void onClick(View v) {
            // TODO Auto-generated method stub
         startActivity(new Intent("com.GicInsurance.mymap"));   
         }
      });
}
}


mymap.java
Code: Select all
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;



public class mymap extends MapActivity implements View.OnClickListener {
   MapController mControl;
   GeoPoint GeoP;
   MapView mapV;
   Button view;
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       first();
   }

   @Override
   protected boolean isRouteDisplayed() {
      // TODO Auto-generated method stub
      return false;
   }
   public void first(){
      try{
      setContentView(R.layout.map);
      view=(Button) findViewById(R.id.button1);
      view.setOnClickListener(this);
      }catch(Exception e){
         e.printStackTrace();
      }
   }
   public void classmap(){
      try{
         mapV=(MapView) findViewById(R.id.mapView);
           mapV.displayZoomControls(true);
           mapV.setBuiltInZoomControls(true);
           mapV.setSatellite(true);
          
           //DPS PARAMETERS
          // double lat = 29.344521;
          // double longi = 48.080807;
           double lat =29.381133;
           double longi = 47.985502;
           GeoP = new GeoPoint((int)( lat * 1E6),(int)(longi * 1E6));
          
           mControl = mapV.getController();
           mControl.animateTo(GeoP);
           mControl.setZoom(18);
         //  mControl.setZoom(13);
   }catch(Exception e){
      e.printStackTrace();
   }
   }
   @Override
   public void onClick(View v) {
      // TODO Auto-generated method stub
      
      }
      
   }
   

when i click button1 then it give me unexpected error
danishjee
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Aug 25, 2011 4:18 pm

Top

Return to Map Tutorials

Who is online

Users browsing this forum: Google [Bot] and 2 guests