+ Reply to Thread
Results 1 to 2 of 2

Thread: How to get GPS coordinates at eclipse when emulator is used

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Default How to get GPS coordinates at eclipse when emulator is used


    Hello all, nice to meet you guys
    I am developing a program that including the GPS function
    but I program it for 2 days and still got error

    so, could you mind to give me some hints?

    here are my code.

    package com.fyp.android.blindsystem;

    import android.app.Activity;
    import android.content.Context;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.widget.Toast;

    public class Check_Location extends Activity implements LocationListener{

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check_location);
    Bundle bundle = this.getIntent().getExtras();
    Toast.makeText(Check_Location.this,bundle.getStrin g("User_id"), Toast.LENGTH_SHORT).show();
    showLocation();
    }
    @Override //When location is changed
    public void onLocationChanged(Location location) {
    Toast.makeText(this, location.toString(), Toast.LENGTH_LONG).show();
    }

    @Override //When User turns off GPS or AGPS
    public void onProviderDisabled(String provider) {

    }

    @Override //When Users turn on GPS or AGPS
    public void onProviderEnabled(String provider) {

    }

    @Override //When GPS or AGPS is changed
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    private LocationManager mgr;

    private void showLocation(){
    mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = mgr.getLastKnownLocation("gps");
    StringBuffer msg = new StringBuffer();
    msg.append("Latitude: ");
    msg.append(Double.toString(location.getLatitude()) ); //get error at here
    msg.append(", Longitude: ");
    msg.append(Double.toString(location.getLongitude() ));
    Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }
    }


    Manifest setting

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fyp.android.blindsystem"
    android:versionCode="1"
    android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".BlindSystem"
    android:label="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <activity android:name="Service"
    android:label="@string/service_title">
    </activity>

    <activity android:name="Check_Location"
    android:label="Your location is">
    </activity>

    </application>
    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOC ATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    </manifest>

    Thanks!!

  2. #2
    Join Date
    Feb 2010
    Posts
    2

    Default Re: How to get GPS coordinates at eclipse when emulator is used


    Does anyone can help me plx?
    Thanks alot

+ Reply to Thread

Similar Threads

  1. Replies: 15
    Last Post: 12-27-2011, 06:50 PM
  2. Replies: 13
    Last Post: 04-24-2011, 01:11 PM
  3. Eclipse and intellisense
    By JCollum in forum Developers General Chat
    Replies: 11
    Last Post: 09-06-2010, 03:40 AM
  4. Eclipse
    By dragonrider8844 in forum Developers General Chat
    Replies: 4
    Last Post: 12-04-2008, 01:57 PM
  5. is there anyone kind enough to help me set up the sdk and eclipse
    By dippedinsauce in forum Developers General Chat
    Replies: 11
    Last Post: 11-11-2008, 08:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts