Android MapView + Tab example
i need to have an mapview on a tab. The attached example shows how to do this if using intents. Now i want to change the zoom level of the mapview(s). How can i do this, although i'm using intents (or is there completely different solution)?
Activity code:
public class TabMapsExample extends TabActivity {
TabHost mTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context ctx = this.getApplicationContext();
//tab 1
mTabHost = getTabHost();
TabSpec tabSpec1 = mTabHost.newTabSpec("tab_test1");
tabSpec1.setIndicator("Map1");
Intent i1 = new Intent(ctx, MapTabView.class);
tabSpec1.setContent(i1);
mTabHost.addTab(tabSpec1);
//tab2
mTabHost = getTabHost();
TabSpec tabSpec2 = mTabHost.newTabSpec("tab_test1");
tabSpec2.setIndicator("Map2");
Intent i2 = new Intent(ctx, MapTabView.class);
tabSpec2.setContent(i2);
mTabHost.addTab(tabSpec2);
//tab 3
mTabHost = getTabHost();
TabSpec tabSpec3 = mTabHost.newTabSpec("tab_test1");
tabSpec3.setIndicator("Map");
Intent i3 = new Intent(ctx, MapTabView.class);
tabSpec3.setContent(i3);
mTabHost.addTab(tabSpec3);
}
}
Layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/maptablayout" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:background="#000000" android:orientation="vertical">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="50px"
android:id="@+id/textview" />
<com.google.android.maps.MapView
android:id="@+id/mapview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:clickable="true"
android:apiKey="" />
</LinearLayout>
</RelativeLayout>
thx
Asked by: John258 | Posted: 24-01-2022
Answer 1
Try to use MapController:
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(10);
See also Using Google Maps in Android
UPDATE
You create several instances of the same layout and there is an issue to get needed instance of MapView by id. Can you just use separate layouts for each tab? or create them dynamically?
Answer 2
@ juri: Can an intent also receive data outside of onCreate()? (for example to set the zoomlevel dynamically during runtime and not just at creation of the intent)
Answered by: Stuart377 | Posted: 25-02-2022Answer 3
Zooming should be possible either by activating the Zoom controls of the MapView and let your user zoom-in or out or instead programmatically by using
mapView.getController().zoomIn();
or
mapView.getController().zoomOut();
or
mapView.getController().setZoom(...);
Alternatively what you can do is to pass your intent extra data from outside. I'm just guessing now, but basically you could do something like
Intent intent = new Intent(this, MyMapActivity.class); //this is just one way of specifying it
intent.putExtra(MyMapActivity.ZOOM_LEVEL_CONSTANT, 10);
startActivity(intent);
Within the onCreate(...) of your MyMapActivity you can then read the passed data like
Bundle retrievedData = this.getIntent().getExtras();
if (retrievedData != null) {
int zoomLevel = retrievedData.getInt(ZOOM_LEVEL_CONSTANT);
mapView.getController.setZoom(zoomLevel);
}
Edit: To populate a tab content dynamically:
TabSpec tabSpec = tabHost.newTabSpec("Android X");
tabSpec.setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
//return the view to add as content
return theView;
}
});
Answered by: Aida827 | Posted: 25-02-2022
Similar questions
user interface - Android Center Layout Hiding Button
I am working on a fairly basic screen layout for my first Android application and running into some issues. My goal is to have a TextView in the top left and top right corner, a large "hello world" TextView in the exact middle of the screen, and then a button at the bottom of the screen. My issue is, to center the "hello world" TextView vertically, I need to set the layout_height="fill_parent". However, this causes the ...
How do I use the opengl interface in Android ndk
If I want to use the opengl interface in android ndk, then will it be possible to show
me a simple tutorial to let me master the android ndk?
I just wanna know how to operate in android ndk first.
user interface - Android Radial / Pie Menu
I am looking to create a radial menu in a game that I am writing. Is there a class or API included to assist with this or an open source solution?
Something like this.
Thank you,
Jake
java native interface - How to load jni from sd card on android 2.1?
I want to load third-party jni library in runtime.
I've tried to load directly from sdcard. It expectedly failed.
I've tried to copy library from sdcard to /data/data/app/ and then
System.load(/data/data/app/libjni.so)
It works on HTC HERO, but fails on HTC Legend with Android 2.1.
it fails during execution of native code and write to log uninformative stack trace
Any other way to do it?
Thats...
android - Add menu option to SMS interface
I'm looking for a way to add a new custom menu item to the SMS interface. The idea is add an option like "Insert predefined message", and control the predefined message from other application.
Is this possible?
user interface - Android action bar like twitter sample
What is the best way to implement action bar like twitter sample UI Pattern.
Twitter for Android: A closer look at Android’s evolving UI patterns
Pattern 4: Action Bar
http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html
user interface - Android - Way to appear bordered text on the TextView?
Is there a way to appear bordered text on the TextView ?
user interface - Make Android Activity looks like dialog
I am trying to open a dialog on widget click. I have solved the problem skinning the activity started on click with android:theme="@android:style/Theme.Dialog". Unfortunately I cannot reach the same look of a dialog.
This is the outcome:
Dialog from widget
Instead, I would like to reach this result (except for ...
user interface - Android Center Layout Hiding Button
I am working on a fairly basic screen layout for my first Android application and running into some issues. My goal is to have a TextView in the top left and top right corner, a large "hello world" TextView in the exact middle of the screen, and then a button at the bottom of the screen. My issue is, to center the "hello world" TextView vertically, I need to set the layout_height="fill_parent". However, this causes the ...
user interface - Android - Adjust screen when keyboard pops up?
I want to be able to adjust my UI screen on Android when the soft keyboard pops up.
So at the minute I have something similiar to the first picture below where I have and EditText at the bottom of the screen and when a user taps the EditText I want the same as what happens in the second picture.
That is that the EditText gets moved up and appears to "sit" on top of the soft keyboard, when the soft keyboard ...
How do I use the opengl interface in Android ndk
If I want to use the opengl interface in android ndk, then will it be possible to show
me a simple tutorial to let me master the android ndk?
I just wanna know how to operate in android ndk first.
user interface - Android - how do I display a list of items in an HTML-like Ordered list?
Still new to Android
I want to display some data as an HTML-like ordered list (non-actionable).
Example;
Item One
Item Two
Item Three
I feel I am missing something obvious.
Thanks,
JD
java - How to obtain MAC address of WiFi network interface?
It seems the java.net.NetworkInterface implementation of android does not have a
byte[] getHardwareAddress() method
http://developer.android.com/reference/java/net/NetworkInterface.html
I've found several forums of people trying to do this with no definitive answer, I need to get a somewhat cross-device UUID, s...
user interface - Android Radial / Pie Menu
I am looking to create a radial menu in a game that I am writing. Is there a class or API included to assist with this or an open source solution?
Something like this.
Thank you,
Jake
java - How to make an Advanced user interface in Android?
i wonder how you can make an advanced Android User interface where you can add for example a drag drop and more graphics options? is that by using OpenGl ?!
this is example of UI in iPhone Apps.
example 1
user interface - Text with gradient in Android
How would I extend TextView to allow the drawing of text with a gradient effect?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android