Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6871897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:51:36+00:00 2026-05-27T03:51:36+00:00

I would like to write an application for people tracking by using GPS in

  • 0

I would like to write an application for people tracking by using GPS in order to send the coordinates (Latitude and Longitude) via SMS to android phone and bring the coordinates values to display the accurate location on Google Map.

The working system is divided into 2 classes
1. SMSReceiver class: receive SMS then convert the coordinates values which are string values to be double values

Here is my code:

package com.google.android;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SMSReceiver extends BroadcastReceiver {

public String slat;
public String slng;
public double dLat;
public double dLng;

public double getLat() {
    return this.dLat;
}

public double getLng() {
    return this.dLng;
}

@Override
public void onReceive(Context context, Intent intent) {
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String position1 = "";            
    if (bundle != null) {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);             
            position1 += msgs[i].getMessageBody().toString();       
        }
        String position2 = position1.substring(position1.indexOf(" ")+1, position1.length());
        slat = position1.substring(position1.indexOf(":")+1, position1.indexOf(" "));
        slng = position2.substring(position2.indexOf(":")+1, position2.indexOf(" "));
        dLat = Double.parseDouble(slat);
        dLng = Double.parseDouble(slng);
    }                         
}
}  

2. Tracking class: bring the double value from SMS receiver class to display the location on Google Map

Here is my code:

package com.google.android;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ZoomControls;

public class TrackingActivity extends MapActivity {
/** Called when the activity is first created. */
private LocationManager locationManager;
private LocationListener locationListener;
private MapView mapView;
private MapController mapController;
private Button btnSatelite;
private Button btnStreet;
private ZoomControls zoomControls;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);

    btnSatelite = (Button)findViewById(R.id.btnSatelite);
    btnSatelite.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
        // TODO Auto-generated method stub
                mapView.setTraffic(false);
                mapView.setSatellite(true);
        }
    }
    );

    btnStreet = (Button)findViewById(R.id.btnStreet);
    btnStreet.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
        // TODO Auto-generated method stub
                mapView.setSatellite(false);
                mapView.setTraffic(true);
        }
    }
    );

    zoomControls = (ZoomControls)findViewById(R.id.zoomControls1);
    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    mapController.zoomIn();
            }
    });
    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    mapController.zoomOut();
            }
    });

    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, locationListener);

    mapView = (MapView)findViewById(R.id.mapview1);
    mapController = mapView.getController();

}

private class MyLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        SMSReceiver Lat = null;
        SMSReceiver Lng = null;

        /*if (location != null) {
            Toast.makeText(getBaseContext(), "Latitude: " + Lat.getLat() + " Longtitude: " + Lng.getLng(), Toast.LENGTH_SHORT).show();
        }*/

        GeoPoint point = new GeoPoint((int) (Lat.getLat() * 1E6),(int) (Lng.getLng() * 1E6));
        mapController.animateTo(point);
        mapController.setZoom(18);

        ...

        mapView.invalidate();
    }

    ...

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
    }

    ...

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

After I received the coordinate values from SMS, there is no location changing displayed on the map. I suppose that it may be because of Tracking class which cannot refer the coordinate values from SMS receiver class. Please give me some advice what should I do to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:51:37+00:00Added an answer on May 27, 2026 at 3:51 am

    Basically I don’t understand your code : I don’t get the point of your SMSReceiver, if you are supposed to receive a new position through SMS you should implement a connection between your SMSReceiver and your MapActivity.

    What you basically do here is to set a function that’s called when your GPS get a new fix (it’s NOT CALLED when you receive a new SMS) :

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, locationListener);
    

    Moreover in your onLocationChanged() you set two object to null and try to access their property which of course should gives you a NullPointerException.

    What I suggest you is to change your SMSReceiver to handle a listener on SMS reception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using HighLine to write my console application and I would like to modify
I would like to write an application that will copy MP3 files to a
I would like to write an simple application able to retrieve some certain data
I would like to write a GUI application for management of information (text documents).
I would like to write a Java terminal application that does screen manipulation. Are
I would like to write an IO intensive application with no underlying OS, running
In order for reuse ability on iOS, I would like to write the logic
I'm trying to write an application that manipulates camera data. I would like to
I would like to write a small program in C# which goes through my
I would like to write some data to a file in Ruby. What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.