android - Finding Current Location and navigate to it not working -
hi develop app find current location , navigate current location. running on real device getting error "unfortunately current location has stopped". why getting error when correct...???? how can overcome it.... regards
main activtiy code
package com.example.routetracker; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.annotation.suppresslint; import android.app.activity; import android.content.context; import android.view.menu; import android.widget.toast; public class mainactivity extends activity { googlemap map; locationmanager lm; @suppresslint("newapi") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); lm = (locationmanager) getsystemservice(context.location_service); map = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)) .getmap(); map.setmylocationenabled(true); locationlistener ll = new locationlistener() { @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } @override public void onlocationchanged(location location) { toast.maketext(getapplicationcontext(), (int) (location.getlatitude() + location.getlongitude()), toast.length_long).show(); map.addmarker(new markeroptions() .position(new latlng(location.getlatitude(), location.getlongitude())) .title("my position") .icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_azure))); map.animatecamera(cameraupdatefactory.newlatlngzoom(new latlng( location.getlatitude(), location.getlongitude()), 15.0f)); } }; lm.requestlocationupdates(locationmanager.gps_provider, 0, 0, ll); } }
manifest is
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.routetracker" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="12" android:targetsdkversion="17" /> <uses-feature android:glesversion="0x00020000" android:required="true" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices" /> <!-- following 2 permissions not required use google maps android api v2, recommended. --> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <permission android:name="com.example.routetracker.maps_receive" android:protectionlevel="signature" /> <uses-permission android:name="com.example.routetracker.permission.maps_receive" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.routetracker.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasydizp29y9vgjmdlgr-po6p0gzuxvukefco" /> </application> </manifest>
xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.mapfragment" /> </linearlayout>
Comments
Post a Comment