2

I am making my semester project Vehicle tracking Using Android Maps. I am looking for some help. I am receiving locations from vehicle via sms what i want is to display location or update map when i get new sms.

I want to ask how it is possible to update map after some interval or at new sms receive.

for example 12.3245678 , 52.3333333 12.3245689 , 52.3333334 12.3245680 , 52.3333335 12.3245682 , 52.3333336

i know about location.getlangitude() and location listner about i think it only update map using getlanitude() and getlantitude() for GPS trancker and network provider.

but how to set GeoPoint manually and update location listener. or take it as how to update at map we have locations data in database that may also help me

Nomi
  • 710
  • 3
  • 11
  • 21

2 Answers2

1
public class SMSNotificationListener extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    // Here you can extract the intent extra ( lat , longs )
    // Even you can check some message code to identify valid message
    // Can call some different MapDisplayActivity with lat , longs 
    // in Intent.putExtra(...)
    }

}

Add the receiver in AndroidManifest -

 <receiver android:name=".SMSNotificationListener">
   <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
 </receiver>

Now in MapDisplayActivity ---

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_map);
  mapView = (MapView) findViewById(R.id.mapview);
  setMaptoProvidedLocation();
}

/**
 * Setting Google Map to provided location 
 */
 private void setMaptoProvidedLocation() {
  Intent intent = getIntent();
  LAT = intent.getIntExtra(DisplayActivity.LAT, DisplayActivity.DEF_LAT);
  LNG = intent.getIntExtra(DisplayActivity.LNG, DisplayActivity.DEF_LNG);

  mapView.setBuiltInZoomControls(true);
  mapView.setSatellite(true);
  mapController = mapView.getController();


  mapController.setZoom(ZOOM_LEVEL - ZOOM_LEVEL / 2);
  GeoPoint vehicleLocation = new GeoPoint(LAT, LNG);
  mapController.animateTo(vehicleLocation);
  // You can also add map overlays ...

}

 //If MapDisplayActivity is in forground and we want to update the new location

  @Override
  public void onNewIntent(Intent intent) {
  super.onNewIntent(intent);
  setIntent(intent);
  Log.d("MapActivity","Got new Data again");
  setMaptoProvidedLocation(false);
  } 
Jambaaz
  • 2,788
  • 1
  • 19
  • 30
  • @Jain how to call setMaptoProvidedLocation() each time to animate map when there would be new message? or it would do it by itself as we are not using locationUpdate listener. i think something will be in onReciver can you please guide me a bit more. – Nomi Jan 17 '13 at 14:43
  • Yes , everytime you need to call setMaptoProvidedLoction() from onnewIntent(Intent intent) function in MapDisplayActivity. – Jambaaz Jan 17 '13 at 14:54
  • @Jain can you tell me how to call i tried but no success till now..i used Intent service = new Intent(context, Main.class); context.startService(service); – Nomi Jan 17 '13 at 19:44
  • why are you using a service...Its simple , at least in your case ...There is one BroadcastReceiver to get the sms and second is MapDisplayActivity to show location over map. So as soon as receiver gets the sms , It would keep sending the data to the MapDisplayActivity. Let me know , If still you face any problem..!! – Jambaaz Jan 18 '13 at 04:56
  • @jain sorry but i am really stuck could you please give me a favor and check this code [link](https://gist.github.com/4568405) i have crated 2 files on is main (Name:"Burraq" with map) and second is SmsReciver at the end of smsreciver class i am getting new locations and i can display using toast thats working fine. but not getting how to setMaptoProvidedLocation() will call again. sorry for my less knowledge about all this i am not good in android. – Nomi Jan 18 '13 at 20:59
  • I have given comments ...plz check and let me know !! – Jambaaz Jan 19 '13 at 18:53
0

Okay, so you are doing a lot of things here.

  1. To intercept a SMS message you need to listen for these. see: Android – Listen For Incoming SMS Messages

  2. To make a map with markers based on the location data, use the google maps api V.2. see: Google Maps Android API v2 this will tell you all you need to know about making maps with markers from location data.

  3. If you want to update the map from a database in a fixed interval, i suggest making an asynctask or a Timer that checks for updates in the database at the desired fixed interval.

Community
  • 1
  • 1
Noloxs
  • 132
  • 2
  • 11
  • i have done first 2 task only trapped in last one. I am not getting how i should update each. location listener is right approach? or it could be done with some other method. if i detect the update how it could update map as i am showing default points right now with control.animateTo(geoPoint); – Nomi Jan 17 '13 at 14:36