Getting started using the MapView, having issues...

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Getting started using the MapView, having issues...

Postby GasBot » Wed Nov 05, 2008 6:59 pm

Alright so I have an app that runs all in one activity. I'm trying to add some Maps functionality so I've created a new class and extended the MapsActivity. I created a map.xml file that uses the mapview and has my apikey and all that in there.

What I need to be able to do is start up the map activity from the first one and then plot some points on the map. I tried setting a new intent using the second activity.class and then saying startActivity(intent) and I'm getting an error somewhere between those two lines.

How can I call a second activity from my first one?

Then beyond that, how can I pass in a lat/long to plot a point on the map? After doing some research it looks like you're not supposed to talk directly from one activity to another, so I'm not sure how to accomplish this.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Top

Postby GasBot » Wed Nov 05, 2008 7:09 pm

Here's my code:

The Map Activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package myPackage;
  2.  
  3.  
  4.  
  5. import com.google.android.maps.MapActivity;
  6.  
  7. import android.os.Bundle;
  8.  
  9.  
  10.  
  11. public class MyMap extends MapActivity {
  12.  
  13.         @Override
  14.  
  15.         public void onCreate(Bundle savedInstanceState) {
  16.  
  17.                 super.onCreate(savedInstanceState);
  18.  
  19.                 setContentView(R.layout.map);
  20.  
  21.         }
  22.  
  23.        
  24.  
  25.         @Override
  26.  
  27.         protected boolean isRouteDisplayed() {
  28.  
  29.                 return false;
  30.  
  31.         }
  32.  
  33.        
  34.  
  35.         public void AddPoint(double latitude, double longitude, String pointName) {
  36.  
  37.                
  38.  
  39.         }
  40.  
  41. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


The function in the first activity that's supposed to call the map
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public void OpenMap(double latitude, double longitude, String pointName) {
  3.  
  4.                 Intent mapIntent = new Intent(thisActivity.this, MyMap.class);
  5.  
  6.                 startActivity(mapIntent);
  7.  
  8.         }
  9.  
  10.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


And the map activity entry in the manifest:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.         <activity android:name=".MyMap"
  3.  
  4.                           android:label="Map Screen">
  5.  
  6.                 <intent-filter>
  7.  
  8.                         <action android:name="android.intent.action.VIEW" />
  9.  
  10.                         <category android:name="android.intent.category.DEFAULT" />
  11.  
  12.                 </intent-filter>
  13.  
  14.         </activity>
  15.  
  16.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I'm thinking that those intent-filters could be what's causing the issue, but I have no clue.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby GasBot » Thu Nov 06, 2008 5:58 pm

C'mon, someone has to know what's going on here.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby linkmaster_6 » Thu Nov 06, 2008 8:48 pm

did you get your api key?
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby GasBot » Thu Nov 06, 2008 11:01 pm

Yep, it's inside my layout XML. Even without the key, I don't think I'd get an error when trying to open the activity, it would just show the all the way zoomed out map.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby GasBot » Thu Nov 06, 2008 11:06 pm

Here's my layout map.xml

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"
  6.  
  7.         android:layout_width="fill_parent"
  8.  
  9.         android:layout_height="fill_parent"
  10.  
  11.         >
  12.  
  13. <com.google.android.maps.MapView
  14.  
  15.         android:id="@+id/mapView"
  16.  
  17.         android:layout_width="fill_parent"
  18.  
  19.         android:layout_height="fill_parent"
  20.  
  21.         android:apiKey="[myapikey]"
  22.  
  23.         />
  24.  
  25. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


That all looks good, right?
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Top

Postby linkmaster_6 » Thu Nov 06, 2008 11:21 pm

no you now need a api key witch you can obtain though lgoogle api
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby GasBot » Thu Nov 06, 2008 11:23 pm

linkmaster_6 wrote:no you now need a api key witch you can obtain though lgoogle api


Yeah, and I have one. I just replaced it in the map.xml that I posted here.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby GasBot » Thu Nov 06, 2008 11:40 pm

Just noticed this error in the debugger...

11-06 15:41:16.735: ERROR/AndroidRuntime(994): Uncaught handler: thread WebViewCoreThread exiting due to uncaught exception
11-06 15:41:17.024: ERROR/AndroidRuntime(994): java.lang.NoClassDefFoundError: my.namespace.MyMap

So I'm guessing that there's something wrong with the MyMap Activity class above. Or possibly with the Intent constructor that calls the MyMap.class. Anyone seen this before?
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby Quetzalcoatl » Fri Nov 07, 2008 12:57 am

11-06 15:41:17.024: ERROR/AndroidRuntime(994): java.lang.NoClassDefFoundError: my.namespace.MyMap

Is MyMap in the same namespace? (is it packages for Java? :oops:). Is there any difference in case between the xml files and the java files/class name?
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby Quetzalcoatl » Fri Nov 07, 2008 1:05 am

Code: Select all
package myPackage;

import com.google.android.maps.MapActivity;
import android.os.Bundle;

public class MyMap extends MapActivity


According to the above, package is 'myPackage' but the running activity is looking in 'my.namespace'. Where is my.namespace defined? I take it that myPackage should be my.namespace.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby GasBot » Fri Nov 07, 2008 1:19 am

Quetzalcoatl wrote:
Code: Select all
package myPackage;

import com.google.android.maps.MapActivity;
import android.os.Bundle;

public class MyMap extends MapActivity


According to the above, package is 'myPackage' but the running activity is looking in 'my.namespace'. Where is my.namespace defined? I take it that myPackage should be my.namespace.


Sorry, I've been replacing the real namespace of the project with placeholders. The package that the "MyMap" class is in is the same as the main activity. Just imagine that they all say the my.namespace. :)
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby Quetzalcoatl » Fri Nov 07, 2008 1:21 am

java.lang.NoClassDefFoundError: my.namespace.MyMap

:)

Does still suggest that it cannot find the class for some reason.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby GasBot » Sun Nov 09, 2008 7:48 pm

I figured out what the problem was!

I needed to put this line:

<uses-library android:name="com.google.android.maps" />

Inside the Application tag of the AndroidManifest.xml.

After I added that it loaded right up.
GasBot
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Fri Oct 17, 2008 7:19 am

Postby Draffodx » Wed Nov 26, 2008 10:25 am

Sorry to hijack the thread (kind of) I didn't think my question warranted a new thread, I have an api key from google but it says its only good for any url in the website that i supplied when I signed up, can I still just use this api key in an Android application or is there extra steps I need to take?
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top
Next

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests