David Tunnell
David Tunnell

Reputation: 7542

Testing functionality of google maps view inside android app

Hello and thanks for looking. I am working on my first android app. In one of the tabs I want a functional version of google maps. As you can see, I am well on my way. However I don't know how to zoom in/type in an address for navigation etc with the emulator to see if it is functioning properly.

enter image description here

Here is the layout xml:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 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/myMapView"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:enabled="true"
     android:clickable="true"
     android:apiKey="myapikey"
   />

 </LinearLayout>

and the java of my map activity:

 import android.os.Bundle;

 import com.google.android.maps.MapActivity;

 public class MapsActivity extends MapActivity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.maps_layout);
     }

     @Override
     protected boolean isRouteDisplayed() {
         // TODO Auto-generated method stub
         return false;
     }
 }

Upvotes: 2

Views: 380

Answers (2)

Ndupza
Ndupza

Reputation: 780

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    TextView myLocationText = (TextView) findViewById(R.id.myLocationText);
    setContentView(R.layout.map);        

    //make available zoom controls
    mapView.setBuiltInZoomControls(true);

    // zoom 1 is top world view
    controller.setZoom(17);
}

You can also hard code the zoom for when the map launches using the last line

Upvotes: 1

Nikola Davidovic
Nikola Davidovic

Reputation: 8656

To turn on zooming you should do the following:

public class MapsActivity extends MapActivity {
     private MapView map;
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.maps_layout);
         map = (MapView) findViewById(R.id.map);
         map.setBuiltInZoomControls(true);
     }

I'm not sure for navigation, the required override for

protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

is this and therefore you can't display a route to the searched place.

Upvotes: 1

Related Questions