Marker Listener on Map in android -
i developing 1 application in displaying locations current location database location in map using markers, trying add listener current location marker,here listener applied current location other database markers effected listener,it raised exception while clicked on database markers in map,my requirement listener applied current location please verify made mistake in code
public class showmapwhenloginactivity extends fragmentactivity implements locationlistener, onmarkerclicklistener{ googlemap _googlemap; latlng myposition; locationmanager locationmanger; private marker mcustomermarker; private double latitude; private double langitude; private string titile = "start"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_show_map_when_login); _googlemap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid( r.id.mapid)).getmap(); locationmanager service = (locationmanager)getsystemservice(location_service); boolean enablegps = service.isproviderenabled(locationmanager.gps_provider); boolean enablewifi= service.isproviderenabled(locationmanager.network_provider); /*if(!enablegps || !enablewifi){ toast.maketext(showmapwhenloginactivity.this, "gps signal not found", toast.length_long).show(); intent intent = new intent(settings.action_location_source_settings); startactivity(intent); }*/ locationmanger = (locationmanager) getsystemservice(context.location_service); criteria criteria = new criteria(); string provider = service.getbestprovider(criteria, true); service.requestlocationupdates(provider, 0, 0, this); if(_googlemap==null){ toast.maketext(getapplicationcontext(), "google map not available", toast.length_long).show(); } _googlemap.setonmarkerclicklistener(this); } @override public void onlocationchanged(location location) { // todo auto-generated method stub //locationmanger.requestlocationupdates(locationmanager.network_provider, 0, 0, this); //_googlemap.clear(); arraylist<hashmap<string, string>> arl = (arraylist<hashmap<string, string>>) getintent().getserializableextra("arraylist"); if(location!=null){ latitude = location.getlatitude(); langitude = location.getlongitude(); latlng latlang = new latlng(latitude, langitude); myposition = new latlng(latitude, langitude); } if(arl.size()!=0){ for(int j = 0;j<arl.size();j++){ string lat =arl.get(j).get("lat").tostring(); string lng =arl.get(j).get("lng").tostring(); if ( !lat.trim().equals("") && !lng.trim().equals("") ) { double hlat = double.parsedouble(lat.trim()); double hlong= double.parsedouble(lng.trim()); latlng dabaselocations =new latlng(hlat, hlong); getotherlocation(dabaselocations); getcurrentlocation(myposition); // show current location database locations } } } else{ // show current location getcurrentlocation(myposition); } } @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 void onrestart() { // todo auto-generated method stub super.onrestart(); intent = new intent(showmapwhenloginactivity.this,showmapwhenloginactivity.class); startactivity(i); finish(); }*/ private void getotherlocation(latlng location){ mcustomermarker = _googlemap.addmarker(new markeroptions() .position(location) .icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_azure)) .flat(true)); } private void getcurrentlocation(latlng location){ _googlemap.movecamera(cameraupdatefactory.newlatlngzoom(myposition,5)); _googlemap.addmarker(new markeroptions().position(location).title(titile)); } @override public boolean onmarkerclick(marker marker) { // todo auto-generated method stub if((marker.gettitle()).equals(titile)){ toast.maketext(showmapwhenloginactivity.this, "clicked", 100).show(); } return true; } }
logcat
03-10 16:17:47.482: e/androidruntime(1395): fatal exception: main 03-10 16:17:47.482: e/androidruntime(1395): java.lang.nullpointerexception 03-10 16:17:47.482: e/androidruntime(1395): @ com.technowellservices.traffic.showmapwhenloginactivity. onmarkerclick(showmapwhenloginactivity.java:172) 03-10 16:17:47.482: e/androidruntime(1395): @ com.google.android.gms.maps.googlemap$8.a(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ c om.google.android.gms.maps.internal.k$a.ontransact(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ android.os.binder.transact(binder.java:310) 03-10 16:17:47.482: e/androidruntime(1395): @ ejn.a(sourcefile:84) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.e.bl.a(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.ay.c.a(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.ay.n.c(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.ay.m.a(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.ay.bg.b(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.ay.bc.onsingletapconfirmed(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.bo.g.onsingletapconfirmed(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ maps.bo.i.handlemessage(unknown source) 03-10 16:17:47.482: e/androidruntime(1395): @ android.os.handler.dispatchmessage(handler.java:130) 03-10 16:17:47.482: e/androidruntime(1395): @ android.os.looper.loop(sourcefile:351) 03-10 16:17:47.482: e/androidruntime(1395): @ android.app.activitythread.main(activitythread.java:3814) 03-10 16:17:47.482: e/androidruntime(1395): @ java.lang.reflect.method.invokenative(native method) 03-10 16:17:47.482: e/androidruntime(1395): @ java.lang.reflect.method.invoke(method.java:538) 03-10 16:17:47.482: e/androidruntime(1395): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) 03-10 16:17:47.482: e/androidruntime(1395): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:659) 03-10 16:17:47.482: e/androidruntime(1395): @ dalvik.system.nativestart.main(native method)
try out below :
@override public boolean onmarkerclick(marker marker) { // todo auto-generated method stub if((marker.equals(mcustomermarker)){ toast.maketext(showmapwhenloginactivity.this, "clicked", 100).show(); } return false; }
Comments
Post a Comment