android - Getting GPS co-ordinates via SMS and show on google map -


i trying show gps co-ordinates on google map. getting gps co-ordinates via sms. building , app generation done correctly after launching app on real device(android kitkat), google map don't show , once receive gps co-ordinates via sms app crashes displaying "unfortunately map has stopped".here code:

import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.os.build; import android.support.v4.app.fragmentactivity; import android.os.bundle; import android.telephony.smsmanager; import android.widget.toast;  import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions;  public class mapsactivity extends fragmentactivity implements      onmapreadycallback {  static private googlemap mmap; int index=0;//index of sms recieved int index2=0; char[] lat=new char[15]; char[] lon=new char[15];   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_maps);     // obtain supportmapfragment , notified when map ready used.     supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager()             .findfragmentbyid(r.id.map);     mapfragment.getmapasync(this); } private broadcastreceiver mreceiver = new broadcastreceiver() {    @override     public void onreceive(context context, intent intent) {      // data (sms data) bound intent         bundle bundle = intent.getextras();      smsmessage[] msgs = null;          string str = "";         string format = bundle.getstring("format");          if (bundle != null)         {             object [] pdus = (object[]) bundle.get("pdus");              msgs= new smsmessage[pdus.length];              (int = 0; < messages.length; i++)             {                 if (build.version.sdk_int >= build.version_codes.m) {                     string format = mybundle.getstring("format");                     messages[i] = smsmessage.createfrompdu((byte[]) pdus[i], format);                 }                // else {                  //   messages[i] = smsmessage.createfrompdu((byte[]) pdus[i]);                 //}                 strmessage += messages[i].getoriginatingaddress();                 strmessage += " : ";                 strmessage += messages[i].getmessagebody();                 index=strmessage.indexof(":");                 index2=strmessage.indexof(",");                 strmessage.getchars(index,index2,lat,0);//extracting latitude latitude: ,                 index=strmessage.lastindexof(":");//getting last index of : longitude:                 index2=strmessage.length();//getting length of string                 strmessage.getchars(index,index2,lon,0);//extracting longitude : last char of string                 strmessage += "\n";             }              toast.maketext(context, strmessage, toast.length_short).show();             update_location();         }             } // bundle null         }  @override public void onmapready(googlemap googlemap) {     mmap = googlemap;      // add marker in sydney , move camera     latlng venkateshnagar = new latlng(20.8781753,15.3481637);     mmap.addmarker(new markeroptions().position(venkateshnagar).title("random location startup"));     mmap.movecamera(cameraupdatefactory.newlatlng(venkateshnagar));     mmap.movecamera(cameraupdatefactory.newlatlngzoom(venkateshnagar,18)); }      void update_location(){  double lat1=double.parsedouble(lat.tostring());  double lon2=double.parsedouble(lon.tostring());     latlng found=new latlng(lat1,lon2);     mmap.addmarker(new markeroptions().position(found).title("this current location"));     mmap.movecamera(cameraupdatefactory.newlatlng(found));     mmap.movecamera(cameraupdatefactory.newlatlngzoom(found,18));     }    } 

what have done wrong.

now working. have used markeroptions options in update_location() method of program. , byusing options.position(found) here updated method:

public void update_loc()    {                                               // instantiating markeroptions class     markeroptions options = new markeroptions();    // toast.maketext(getapplicationcontext(), lat.tostring()+lon.tostring(), toast.length_long).show();     double lat1=double.parsedouble(lat);     double lon2=double.parsedouble(lon);     latlng found=new latlng(lat1,lon2);     options.position(found);     marker mapmarker=mmap.addmarker(options);     options.title("this current location");     mmap.movecamera(cameraupdatefactory.newlatlngzoom(found,26)); } 

i hope others trying make application me.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -