Basic Map-Application

Tutorials that use the MapActivity. Many using GPS functionality.

i cannot see my MapView

Postby tannadevang » Sun May 11, 2008 11:27 pm

Hi,
I am not sure if i am doing it right, but i do not see my Map when i start my Map application.

My main.xml looks like
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.  
  3.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  
  5.    android:orientation="vertical" android:layout_width="fill_parent"  
  6.  
  7.    android:layout_height="fill_parent">  
  8.  
  9.    
  10.  
  11.            <view class="com.google.android.maps.MapView"
  12.  
  13.           android:layout_width="fill_parent"  
  14.  
  15.           android:layout_height="fill_parent"  
  16.  
  17.           android:layout_weight="1" />  
  18.  
  19.          
  20.  
  21.            <EditText android:layout_width="fill_parent"  
  22.  
  23.            android:layout_height="wrap_content"  
  24.  
  25.                 android:text="enter address to search..."  
  26.  
  27.                  android:selectAllOnFocus="true"/>  
  28.  
  29.         </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


and my MapActivity file is


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class BasicMappActivity extends MapActivity {
  2.  
  3.   private MapView myMapView;
  4.  
  5.         public void onCreate(Bundle icicle) {
  6.  
  7.                 super.onCreate(icicle);
  8.  
  9.                 myMapView = new MapView(this);
  10.  
  11.                 Point p = new Point ((int)(40.692158 * 1000000),(int)(-74.042616*1000000));
  12.  
  13.                 MapController mc = myMapView.getController();
  14.  
  15.                 mc.animateTo(p);
  16.  
  17.                 mc.zoomTo(20);
  18.  
  19.                 setContentView(R.layout.main);
  20.  
  21.                 myMapView.toggleSatellite();
  22.  
  23.                
  24.  
  25.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Am i missing anything here ?
tannadevang
Freshman
Freshman
 
Posts: 2
Joined: Sun May 11, 2008 11:06 pm
Location: San Jose

Top

Map problem

Postby manju » Tue Jun 10, 2008 5:27 am

hi...
I have a problem in running this program. I guess the error is in xml file particularly in activity.
The error is in following manner displayed in a different window.

"This Launch Configuration is setup to start activity google.programs.google.
This activity is not defined by the manifest:launch aborted!"

pls come to my help...
manju
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Jun 09, 2008 9:38 am
Location: banglore

hi

Postby manju » Wed Jun 25, 2008 7:11 am

problem solved......... :D :D
manju
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Jun 09, 2008 9:38 am
Location: banglore

Postby phannguyen » Mon Aug 04, 2008 4:39 am

hi plusminus,
i can't see any map loaded on my emulator.
My network connect well,what's wrong here?it's only available on US, right?
please help me explain this problem, it seem i can't run any app related to map :( .
thanks a lot.
Attachments
minimap.JPG
minimap.JPG (39.72 KiB) Viewed 6913 times
PhanNguyen
phannguyen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Thu Jul 17, 2008 7:37 am

Postby Gurbuh » Wed Sep 10, 2008 9:53 pm

Hi. I've been trying to create a map application for the past 2 days, but all i get is the "The application map (process com.android.map) has stopped unexpectedly. Please try again" error. Now I even tried just copy-pasting your code but I still get the same error. I did change the code a little as ZoomTo and Point don't seem to exist in 0.9 beta.

Here's my code:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.map;
  2.  
  3.  
  4.  
  5. import android.os.Bundle;
  6.  
  7. import android.view.KeyEvent;
  8.  
  9.  
  10.  
  11. import com.google.android.maps.GeoPoint;
  12.  
  13. import com.google.android.maps.MapActivity;
  14.  
  15. import com.google.android.maps.MapController;
  16.  
  17. import com.google.android.maps.MapView;
  18.  
  19. import com.google.common.geom.Point;
  20.  
  21.  
  22.  
  23. public class map 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.         // Make myMapView the exilicit view of this app
  58.  
  59.         setContentView(myMapView);
  60.  
  61.         // Enable Sattelite-Mode, so we will se the
  62.  
  63.         // Statue of liberty instantly on the screen
  64.  
  65.         myMapView.setSatellite(true);
  66.  
  67.     }
  68.  
  69.  
  70.  
  71.         @Override
  72.  
  73.         protected boolean isRouteDisplayed() {
  74.  
  75.                 // TODO Auto-generated method stub
  76.  
  77.                 return false;
  78.  
  79.         }
  80.  
  81. }
  82.  
  83.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I hope anyone can see what's wrong with it.
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby plusminus » Thu Sep 11, 2008 2:20 am

Did you add the 'uses-library' to the Manifest, like:

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.andnav.apk">
  6.  
  7.     <application android:icon="@drawable/icon">
  8.  
  9.                 <uses-library android:name="com.google.android.maps" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


It's required since SDK 0.9 .

Regards,
plusminus
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 Gurbuh » Thu Sep 11, 2008 9:20 am

No I didn't . I didn't know that it was required. Will try that. Maybe you could update the tutorial with this info, so people don't get the same problem in the future. Thanks!
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby plusminus » Thu Sep 11, 2008 2:26 pm

Gurbuh wrote:No I didn't . I didn't know that it was required. Will try that. Maybe you could update the tutorial with this info, so people don't get the same problem in the future. Thanks!


I added a hit, that it is updated and solutions can be found in the responses. Thats all time I can afford now. :(
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 Gurbuh » Thu Sep 11, 2008 3:24 pm

Ok. I still haven't got it to work by the way. At least my application starts now, but it shows no map. I have the same as the guy above. Just a blank google maps screen with a dot in the middle.
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby cadlg » Thu Sep 11, 2008 4:03 pm

If you use a proxy to go out to the internet, that could be the reason of your blank screen.
I remember this was discussed some time ago here in anddev.
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Postby Gurbuh » Thu Sep 11, 2008 4:45 pm

I'm not going to internet. Should i be doing that? It's not in the tutorial. I just want the same effect as when you click on Maps in the home screen of Android
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby plusminus » Thu Sep 11, 2008 6:34 pm

Gurbuh wrote:I'm not going to internet. Should i be doing that? It's not in the tutorial. I just want the same effect as when you click on Maps in the home screen of Android


You need an working internet-connection to load the map-tiles :!:
Or did I missunderstand you...
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 Gurbuh » Thu Sep 11, 2008 9:55 pm

I guess I misunderstood you. I thought that the maps where loaded from the same 'database' as the standard Google Maps application. :oops: I'll go and fix a connection now then. Thanks again.
(By the way, I'm not doing this just for myself. I am trying to make the Dutch equivalent of anddev.org. I hope to inspire Dutch coders like this website inspired me :D )
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby Marchu » Sat Sep 27, 2008 4:18 pm

plusminus wrote:
Gurbuh wrote:I'm not going to internet. Should i be doing that? It's not in the tutorial. I just want the same effect as when you click on Maps in the home screen of Android


You need an working internet-connection to load the map-tiles :!:
Or did I missunderstand you...


It looks like you need some permissions to load the map-tiles..
Just discover this, and it works and loads the tiiles :-)

Add this in your AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  2.   <uses-permission android:name="android.permission.INTERNET" />
  3.   <uses-permission android:name="android.permission.ACCESS_GPS" />
  4.   <uses-permission android:name="android.permission.ACCESS_LOCATION" />
  5.   <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
  6.   <uses-permission android:name="android.permission.ACCESS_CELL_ID" />
  7.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Don't know if you need all of those permissions, but works.

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

Map tutorial to 1.0

Postby Marchu » Sat Sep 27, 2008 4:51 pm

Here is the updated code from the example at the beginning of this thread, for use with the 1.0 SDK.
I just started with Android, and learning with a changed SDK is strugling.
So, i hope others can use this :)

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


p.s. it works with zoom in and out,with the keyboard keys (in the simulator), but the toggle for satelite and traffic is not yet working (don't know why not at the moment).
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Top
PreviousNext

Return to Map Tutorials

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests