Toying with MapView

by Alvin Yates » Wed, 19 Nov 2008 18:48:31 GMT


Sponsored Links
 Decided to toy with the Map API while I clean up my current app.  So I
made a simple MapView and was kinda intrigued to notice a couple
things, so I'm making sure this is default behavior and not me
breaking something:

1) Is there no default set of buttons for pan/zoom?  I had to manually
add zoom myself, but pan will be annoying.

2) My Back button does not work.  In order to quit my app, I had to
actually hit Home.  Is this normal?

--~--~---------~--~----~------------~-------~--~----~



Toying with MapView

by Mark Murphy » Wed, 19 Nov 2008 20:44:52 GMT


 


There are no buttons for pan. Make sure you have 
android:clickable="true" on the com.google.android.maps.MapView in your 
layout, and pan just works by dragging the map.


Not that I'm aware of. In the map example in my book, I didn't notice 
that the back button didn't work.

Are you overriding onKeyDown() or kin? If so, are you chaining to the 
superclass for all key events you aren't handling?

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Toying with MapView

by Alvin Yates » Thu, 20 Nov 2008 03:39:13 GMT


 Lovely.  I did happen to forget the super.onKeyDown() call.  And the
map dragging works just fine now.

So as far as Zoom is concerned, I have displayZoomControls() set to
true in my MapActivity.  Is there something else I need to do to get
that to appear/work as expected?





--~--~---------~--~----~------------~-------~--~----~



Toying with MapView

by Mark Murphy » Thu, 20 Nov 2008 04:37:57 GMT


 


Ah, sorry, I thought you had that working, based on your original email.

You need to actually add them to the view where you want them to go.

For example, here's a layout with a spot for the zoom controls in the 
lower-left:

<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android" ;
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <com.google.android.maps.MapView android:id="@+id/map"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:apiKey="00yHj0k7_7vzDDmwgQLGkUa7oJbRal2t7bWIkWw"
                android:clickable="true" />
        <LinearLayout android:id="@+id/zoom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true" />
</RelativeLayout>

Here's the piece of onCreate() code that plops the zoom controls into 
the LinearLayout shown above:

ViewGroup zoom=(ViewGroup)findViewById(R.id.zoom);
        
zoom.addView(map.getZoomControls());

If you want a full MapView project that implements all of this, head on 
over to:

 http://commonsware.com/Android/ 

and download the source code to Version 1.4. Maps/NooYawk is the project 
you're looking for inside the source ZIP.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



Toying with MapView

by Alvin Yates » Fri, 21 Nov 2008 08:42:56 GMT


 Just downloaded it.  Looks pretty good, although the map doesn't
display, just the markers.  What is funny though is that when I added
in menu code to my app, it doesn't display.  However, it does display
in your app.  I'm wondering if the menu is considered an overlay?  Or
if there is yet another small item of code I am missing to put this
thing to bed.





--~--~---------~--~----~------------~-------~--~----~



Toying with MapView

by Mark Murphy » Fri, 21 Nov 2008 08:51:45 GMT


 


If you haven't done so already, you have to put in your own apiKey. I 
keep forgetting that step, since it's new.

If you look in the layout, you'll see:

android:apiKey="00yHj0k7_7vzDDmwgQLGkUa7oJbRal2t7bWIkWw"

That key won't work on your PC. If you got an apiKey for your own 
MapView app, just use it -- the key is based on the PC, not the app.

Otherwise, visit:

 http://code.google.com/android/toolbox/apis/mapkey.html 

and pick up a key.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!

--~--~---------~--~----~------------~-------~--~----~



Toying with MapView

by Alvin Yates » Fri, 21 Nov 2008 08:54:00 GMT


 That explains it.  I thought it was based on the app.

*The More You Know*





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Our app force closes on 1.6, Is SDK or image available yet?

We have had a couple users on the myTouch phone have issues in our
application. It apparently is force closing on them. I am not sure of
why it is, and the 1.6 SDK is not out yet. Has 1.6 been released into
the wild? If so, do you know where I can download the image for my G1
dev phone to test w/?

Thanks,

Chris
--~--~---------~--~----~------------~-------~--~----~

2. ColorStateList creation

I want to create color state list from xml file containing a selector.
ColorStateList createFromXml(Resources r, XmlPullParser parser) but i
can't figure out what parameters to pass. I guess i can use :
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
to obtain the parser but what about the xml file that i want to parse.
Thanks
--~--~---------~--~----~------------~-------~--~----~

3. How to open or close the soft keyboard by code

4. Drawable tilemode repat only vertically

5. How to open or close the soft keyboard by code

6. Any Twitter clients supporting ACTION_SEND?

7. Recommended uses of a class extending android.app.Application