gps not working

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

gps not working

Postby xiaodar » Mon May 31, 2010 6:50 am

i have this application which is suppose to display the current location of my position with a blue dot on the map.
It works on the emulator using emulator control.
However when i tried it out on the atcual phone device itself.
It promps me an error asking me to force close the application.

HelloMapView.java
Code: Select all
package com.learn2develop;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

public class HelloMapView extends MapActivity {
   
   LinearLayout linearLayout;
   MapView mapView;
   ZoomControls mZoom;
   
   List<Overlay> mapOverlays;
   Drawable drawable;
   HelloItemizedOverlay itemizedOverlay;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        linearLayout = (LinearLayout) findViewById(R.id.zoomview);
        mapView = (MapView) findViewById(R.id.mapview);
        mZoom = (ZoomControls) mapView.getZoomControls();
        linearLayout.addView(mZoom);
       
        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.androidmarker);
 
        itemizedOverlay = new HelloItemizedOverlay(this, drawable);


       
        GeoPoint point3 = new GeoPoint(1300241,103838438);
        OverlayItem overlayitem3 = new OverlayItem(point3, "test5", "test6");
        //1.300241,103.838438   313
       
        GeoPoint point4 = new GeoPoint(1301809,103836601);
        OverlayItem overlayitem4 = new OverlayItem(point4, "test7", "test8");
        //1.301809,103.836601 cine
       
        GeoPoint point5 = new GeoPoint(1307142,103833619);
        OverlayItem overlayitem5 = new OverlayItem(point5, "test9", "test10");
       // 1.307142,103.833619 far east
       
        GeoPoint point6 = new GeoPoint(1304254,103832452);
        OverlayItem overlayitem6 = new OverlayItem(point6, "test11", "test12");
       // 1.304254,103.832452 orchard
       
        GeoPoint point7 = new GeoPoint(1302643,103834603);
        OverlayItem overlayitem7 = new OverlayItem(point7, "test13", "test14");
        //1.302643,103.834603
       
        GeoPoint point8 = new GeoPoint(1301013,103845465);
        OverlayItem overlayitem8 = new OverlayItem(point8, "test15", "test16");
        //1.301013,103.845465 plaza sing
       
        itemizedOverlay.addOverlay(overlayitem3);
        itemizedOverlay.addOverlay(overlayitem4);
        itemizedOverlay.addOverlay(overlayitem5);
        itemizedOverlay.addOverlay(overlayitem6);
        itemizedOverlay.addOverlay(overlayitem7);
        itemizedOverlay.addOverlay(overlayitem8);
       
       
        MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this,mapView);
        myLocationOverlay.enableMyLocation();
        mapView.getOverlays().add(itemizedOverlay);
        mapOverlays.add(myLocationOverlay);
       
      //  myLocationOverlay = new MyLocationOverlay(this,yourMapView);
      //  myLocationOverlay.enableMyLocation();
      //  yourMapView.getOverlays().add(myLocationOverlay);
       
    }

   @Override
   protected boolean isRouteDisplayed() {
      // TODO Auto-generated method stub
      return false;
   }

   
}


HelloItemizedOverlay .java
Code: Select all
package com.learn2develop;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {
   
   private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
   private Context mContext;


   public HelloItemizedOverlay(Drawable defaultMarker) {
      super(boundCenterBottom(defaultMarker));
      // TODO Auto-generated constructor stub
   }

   @Override
   protected OverlayItem createItem(int i) {
      // TODO Auto-generated method stub
       return mOverlays.get(i);
      

   }

   @Override
   public int size() {
      // TODO Auto-generated method stub
      return mOverlays.size();
   }

   public void addOverlay(OverlayItem overlay) {
       mOverlays.add(overlay);
       populate();
   }

   @Override
   protected boolean onTap(int pIndex) {
      
      Toast.makeText(mContext, mOverlays.get(pIndex).getSnippet(),
           Toast.LENGTH_LONG).show();
      return true;
   }
   public HelloItemizedOverlay(Context context, Drawable defaultMarker) {
       super(boundCenterBottom(defaultMarker));
       mContext = context;
   }

   

}


Main.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7.  <com.google.android.maps.MapView
  8.        android:id="@+id/mapview"
  9.        android:layout_width="fill_parent"
  10.        android:layout_height="fill_parent"
  11.        android:clickable="true"
  12.        android:apiKey="0j5tYJai2sXmANTGvYmeaIQ9uGVeZXZlCTcScYQ"
  13.    />
  14. <LinearLayout
  15.    android:id="@+id/zoomview"
  16.    android:layout_width="wrap_content"
  17.    android:layout_height="wrap_content"
  18.    android:layout_alignBottom="@id/mapview"
  19.    android:layout_centerHorizontal="true"
  20. />
  21.  
  22.  
  23.  
  24. </RelativeLayout>
  25.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



Manifest file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="com.learn2develop"
  4.      android:versionCode="1"
  5.      android:versionName="1.0">
  6.          <uses-permission android:name="android.permission.INTERNET" />
  7.                 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
  8.                 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
  9.                 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>           
  10.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  11.     <uses-library android:name="com.google.android.maps" />
  12.         <activity android:name=".HelloMapView"
  13.                  android:label="@string/app_name">
  14.             <intent-filter>
  15.                 <action android:name="android.intent.action.MAIN" />
  16.                 <category android:name="android.intent.category.LAUNCHER" />
  17.             </intent-filter>
  18.         </activity>
  19.  
  20.     </application>
  21.  
  22.  
  23. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
xiaodar
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Mar 24, 2010 9:51 am

Top

Re: gps not working

Postby JKumar » Tue Jun 01, 2010 9:21 am

Hi,

Can you post the DDMS log for the exception to understand better?
Hope the suggestion helps you
Keep posting .It makes us better to understand Android
User avatar
JKumar
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Thu May 13, 2010 8:17 am
Location: INDIA

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests