Basic Map-Application

Tutorials that use the MapActivity. Many using GPS functionality.

Postby ninor » Sat Sep 27, 2008 7:11 pm

Thanks Marchu!
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Postby phannguyen » Fri Oct 03, 2008 7:43 am

hi all,
i have a problem with mapview. in old version mapview work well, but in SDK 1.0 mapview not work.
Now with SDk 1.0 mapview not show,not toggle for satellite, it's only blank screen.

my code same Marchu's code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.example;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.KeyEvent;
  10.  
  11.  
  12.  
  13. import com.google.android.maps.GeoPoint;
  14.  
  15. import com.google.android.maps.MapActivity;
  16.  
  17. import com.google.android.maps.MapController;
  18.  
  19. import com.google.android.maps.MapView;
  20.  
  21. import android.graphics.Point;
  22.  
  23. public class BasicMap extends MapActivity {
  24.  
  25.         private MapView myMapView;
  26.  
  27.  
  28.  
  29.     @Override
  30.  
  31.     public void onCreate(Bundle icicle) {
  32.  
  33.         super.onCreate(icicle);
  34.  
  35.         myMapView = new MapView(this, "key?");
  36.  
  37.  
  38.  
  39.         // Lets start at the Statue of Liberty
  40.  
  41.         // I grabbed the data from Google-Maps
  42.  
  43.         GeoPoint p = new GeoPoint((int) (40.689213 * 1000000),
  44.  
  45.                               (int) (-74.044558 * 1000000));
  46.  
  47.         // Get the controller, that is used for translation and zooming
  48.  
  49.         MapController mc = myMapView.getController();
  50.  
  51.         // Translate to the Statue of Liberty
  52.  
  53.         mc.animateTo(p);
  54.  
  55.         // Zoom Very close
  56.  
  57.         mc.setZoom(21);
  58.  
  59.         // Make myMapView the exilicit view of this app
  60.  
  61.         setContentView(myMapView);
  62.  
  63.         // Enable Sattelite-Mode, so we will se the
  64.  
  65.         // Statue of liberty instantly on the screen
  66.  
  67.         myMapView.setSatellite(true);
  68.  
  69.     }
  70.  
  71.  
  72.  
  73.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  74.  
  75.         if (keyCode == KeyEvent.KEYCODE_I) {
  76.  
  77.             // Zooming In
  78.  
  79.             myMapView.getController().zoomIn();
  80.  
  81.             return true;
  82.  
  83.         } else if (keyCode == KeyEvent.KEYCODE_O) {
  84.  
  85.             // Zooming Out
  86.  
  87.             myMapView.getController().zoomOut();
  88.  
  89.             return true;
  90.  
  91.         } else if (keyCode == KeyEvent.KEYCODE_S) {
  92.  
  93.           // Switch to satellite view
  94.  
  95.           myMapView.setSatellite(true);;
  96.  
  97.             return true;
  98.  
  99.         } else if (keyCode == KeyEvent.KEYCODE_T) {
  100.  
  101.             // Switch on traffic overlays
  102.  
  103.             myMapView.setTraffic(true);
  104.  
  105.             return true;
  106.  
  107.         }
  108.  
  109.         return false;
  110.  
  111.     }
  112.  
  113.  
  114.  
  115.      @Override
  116.  
  117.      protected boolean isRouteDisplayed() {
  118.  
  119.           // TODO Auto-generated method stub
  120.  
  121.           return false;
  122.  
  123.      }
  124.  
  125. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


my Manifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.      package="com.google.android.example"
  6.  
  7.      android:versionCode="1"
  8.  
  9.      android:versionName="1.0.0">
  10.  
  11.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  12.  
  13.     <uses-library android:name="com.google.android.maps"/>
  14.  
  15.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  16.  
  17.     <uses-permission android:name="android.permission.INTERNET" />
  18.  
  19.         <activity android:name=".BasicMap"
  20.  
  21.                  android:label="@string/app_name">
  22.  
  23.             <intent-filter>
  24.  
  25.                 <action android:name="android.intent.action.MAIN" />
  26.  
  27.                 <category android:name="android.intent.category.LAUNCHER" />
  28.  
  29.             </intent-filter>
  30.  
  31.         </activity>
  32.  
  33.     </application>
  34.  
  35. </manifest>
  36.  
  37.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


what wrong here?please help me.
thanks a lot.
Attachments
map_error.JPG
map_error.JPG (44.29 KiB) Viewed 9184 times
PhanNguyen
phannguyen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Thu Jul 17, 2008 7:37 am

Postby Marchu » Sat Oct 04, 2008 10:26 pm

Hello,

Check your permissions. (i wrote that in a reply above the one with the 1.0 code)
To see the map you need the folowing permissions.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  3.  
  4.   <uses-permission android:name="android.permission.INTERNET" />
  5.  
  6.   <uses-permission android:name="android.permission.ACCESS_GPS" />
  7.  
  8.   <uses-permission android:name="android.permission.ACCESS_LOCATION" />
  9.  
  10.   <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
  11.  
  12.   <uses-permission android:name="android.permission.ACCESS_CELL_ID" />
  13.  
  14.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


I wrote also that the toggle didn't worked. (at the time of writing that, i had just started with the Android SDK)
You can let it work by writing some code with it, what is doing something like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if (myMapView.getSatellite != true) {
  3.  
  4.      myMapView.setsatelite(true);
  5.  
  6. }
  7.  
  8. else{
  9.  
  10.      myMapView.setTrafic(true);
  11.  
  12. }
  13.  
  14.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


I hope this helps.

Cheers
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Postby phannguyen » Mon Oct 06, 2008 2:57 am

hi Marchu,
i have just fixed this bug.cause's i have put wrong place of permission.
write:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.      package="com.google.android.example"
  4.  
  5.      android:versionCode="1"
  6.  
  7.      android:versionName="1.0.0">
  8.  
  9.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  10.  
  11.     <uses-permission android:name="android.permission.INTERNET" />
  12.  
  13.      
  14.  
  15.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  16.  
  17.     <uses-library android:name="com.google.android.maps"/>...
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

instead of
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.      package="com.google.android.example"
  6.  
  7.      android:versionCode="1"
  8.  
  9.      android:versionName="1.0.0">
  10.  
  11.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  12.  
  13.     <uses-library android:name="com.google.android.maps"/>
  14.  
  15.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  16.  
  17.     <uses-permission android:name="android.permission.INTERNET" />...
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

anyway ,thanks for your help.
PhanNguyen
phannguyen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Thu Jul 17, 2008 7:37 am

Postby linkmaster_6 » Wed Oct 22, 2008 9:06 pm

could you please rewrite this tutorial again but with your xml file please? or allow us to download your code?
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby plusminus » Wed Oct 22, 2008 11:54 pm

linkmaster_6 wrote:could you please rewrite this tutorial again but with your xml file please? or allow us to download your code?


I would, definitely if I had enough time :(
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby linkmaster_6 » Fri Oct 24, 2008 8:42 pm

plusminus wrote:
linkmaster_6 wrote:could you please rewrite this tutorial again but with your xml file please? or allow us to download your code?


I would, definitely if I had enough time :(


eh thats fine thank you anyway hopefully someone will help me.
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby rgesnot » Sun Oct 26, 2008 7:11 pm

Hello,

1) When I create a new project and copy-paste the source code, It doesn"t work.

Image

2) When I want to "Sign Up for the Android Maps API", I haven't the "certificate's MD5 fingerprint".
I try it, but without result.
Could you help me also for this topic.


Best regards,
Régis
rgesnot
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Oct 26, 2008 7:08 pm

Postby plusminus » Sun Oct 26, 2008 8:51 pm

Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby zmeda » Fri Nov 21, 2008 9:59 am

Hey!

I have the same problem.
I have double-checked that my apiKey is correct.
In my LogCat i can see 1 warning about Maps
11-21 09:51:39.481: WARN/Maps_Persistence(1939): Couldn't find file: /data/data/iu.android/files/DATA_Tiles

Any1?

Regards
zmeda
Freshman
Freshman
 
Posts: 4
Joined: Fri Nov 21, 2008 9:54 am

Postby zmeda » Mon Nov 24, 2008 9:02 am

Hi.

Is it necessary that GoogleMap is defined in XML of layout or is it OK just to create java object and assign it within MapActivity with setContentView method?

10x
zmeda
Freshman
Freshman
 
Posts: 4
Joined: Fri Nov 21, 2008 9:54 am

Postby worry » Sat Dec 06, 2008 12:39 am

Hi.

I made the same application but I have blank screen (no map), as described before.
I've tried both on emulator and G1 (both have internet connection).
Any Ideas? May be my key is wrong? How do I check it?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.anddev.android.basicmapapp;
  2.  
  3.  
  4.  
  5. import android.os.Bundle;
  6.  
  7. import com.google.android.maps.MapActivity;
  8.  
  9. import com.google.android.maps.MapController;
  10.  
  11. import com.google.android.maps.MapView;
  12.  
  13. import com.google.android.maps.GeoPoint;
  14.  
  15. import org.anddev.android.basicmapapp.R;
  16.  
  17.  
  18.  
  19. public class BasicMapApp extends MapActivity {
  20.  
  21.         private MapView myMapView;
  22.  
  23.  
  24.  
  25.     @Override
  26.  
  27.     public void onCreate(Bundle savedInstanceState) {
  28.  
  29.         super.onCreate(savedInstanceState);
  30.  
  31.         setContentView(R.layout.main);
  32.  
  33.         myMapView = new MapView(this,"xxxxxxxxxxxxxxxxxxx");
  34.  
  35.         GeoPoint p = new GeoPoint((int) (40.689213 * 1000000), (int) (-74.044558 * 1000000));
  36.  
  37.         MapController mc = myMapView.getController();
  38.  
  39.         mc.animateTo(p);
  40.  
  41.         mc.setZoom(20);
  42.  
  43.         setContentView(myMapView);
  44.  
  45.         myMapView.setSatellite(true);
  46.  
  47.    }
  48.  
  49.     @Override
  50.  
  51.     protected boolean isRouteDisplayed() { return false; }
  52.  
  53. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <!-- This is the "Main-Layout" a relative one -->
  4.  
  5. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.                android:layout_width="fill_parent"
  8.  
  9.                android:layout_height="fill_parent">
  10.  
  11.  
  12.  
  13.    
  14.  
  15. </RelativeLayout>
  16.  
  17.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.      package="org.anddev.android.basicmapapp"
  6.  
  7.      android:versionCode="1"
  8.  
  9.      android:versionName="1.0.0">
  10.  
  11.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  12.  
  13.     <uses-library android:name="com.google.android.maps"/>
  14.  
  15.    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  16.  
  17.   <uses-permission android:name="android.permission.INTERNET" />
  18.  
  19.   <uses-permission android:name="android.permission.ACCESS_GPS" />
  20.  
  21.   <uses-permission android:name="android.permission.ACCESS_LOCATION" />
  22.  
  23.   <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
  24.  
  25.   <uses-permission android:name="android.permission.ACCESS_CELL_ID" />
  26.  
  27.         <activity android:name=".BasicMapApp"
  28.  
  29.                  android:label="@string/app_name">
  30.  
  31.             <intent-filter>
  32.  
  33.                 <action android:name="android.intent.action.MAIN" />
  34.  
  35.                 <category android:name="android.intent.category.LAUNCHER" />
  36.  
  37.             </intent-filter>
  38.  
  39.         </activity>
  40.  
  41.     </application>
  42.  
  43. </manifest>  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
worry
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Nov 28, 2008 12:06 am

Postby wilken » Mon Feb 02, 2009 9:18 pm

Did anyone find out what is going on here? i have the same problem.

i have a valid key and the COARSE and INTERNET permissions and get the same blank screen
wilken
Developer
Developer
 
Posts: 35
Joined: Wed Oct 08, 2008 8:22 am

Postby wilken » Mon Feb 02, 2009 10:08 pm

wilken wrote:Did anyone find out what is going on here? i have the same problem.

i have a valid key and the COARSE and INTERNET permissions and get the same blank screen


aha! i had made a valid production key with the keystore i sign my apps with.

You need to make the key from the android debug keystore to get it to work in the emulator.

http://code.google.com/android/toolbox/ ... ingerprint

worked for me!
wilken
Developer
Developer
 
Posts: 35
Joined: Wed Oct 08, 2008 8:22 am

Postby zmeda » Tue Feb 03, 2009 1:21 pm

I'm still struggling problems, that i have white-grey screen with a Google sign on the bottom-left corner.
My ApiKey is correct and OK. I have tried test/dummy map application with that Key and it works.
In my logcat (of original app) i can find this warnings:
02-03 13:08:34.537: WARN/Maps_Persistence(202): Couldn't find file: /data/data/{project}/files/DATA_Preferences
02-03 13:08:34.559: WARN/Maps_Persistence(202): Couldn't find file: /data/data/{project}/files/DATA_Tiles
02-03 13:08:34.568: WARN/Maps(202): Couldn't restore map info, data == null

When I try this test/dummy map application, my logcat does not show these 3 warnings.
I have multi threaded application. Can be multi threading cause of the problem?

Any1?
zmeda
Freshman
Freshman
 
Posts: 4
Joined: Fri Nov 21, 2008 9:54 am

Top
PreviousNext

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests