Created
January 15, 2014 05:08
-
-
Save ishitcno1/8431147 to your computer and use it in GitHub Desktop.
Use baidu loc sdk to get location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" > | |
<TextView | |
android:id="@+id/main_info" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:onClick="getLocation" | |
android:text="Get Location" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.edinstudio.app.location" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk | |
android:minSdkVersion="10" | |
android:targetSdkVersion="19" /> | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.READ_PHONE_STATE" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" > | |
</uses-permission> | |
<uses-permission android:name="android.permission.READ_LOGS" > | |
</uses-permission> | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="com.edinstudio.app.location.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> | |
<service | |
android:name="com.baidu.location.f" | |
android:enabled="true" | |
android:process=":remote" > | |
</service> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.edinstudio.app.location; | |
import android.os.Bundle; | |
import android.support.v7.app.ActionBarActivity; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.TextView; | |
import com.baidu.location.BDLocation; | |
import com.baidu.location.BDLocationListener; | |
import com.baidu.location.LocationClient; | |
public class MainActivity extends ActionBarActivity implements BDLocationListener { | |
public static final String TAG = "LOGE"; | |
private LocationClient mLocationClient; | |
private TextView mTvInfo; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mTvInfo = (TextView) findViewById(R.id.main_info); | |
mLocationClient = new LocationClient(this); | |
mLocationClient.setAK("your key"); | |
mLocationClient.registerLocationListener(this); | |
} | |
public void getLocation(View view) { | |
mLocationClient.start(); | |
if (mLocationClient != null && mLocationClient.isStarted()) { | |
mLocationClient.requestLocation(); | |
} else { | |
Log.e(TAG, "location client is null or not started"); | |
} | |
} | |
@Override | |
public void onReceiveLocation(BDLocation location) { | |
if (location == null) | |
return; | |
StringBuilder sb = new StringBuilder(); | |
sb.append("time: "); | |
sb.append(location.getTime()); | |
sb.append("\nerror code : "); | |
sb.append(location.getLocType()); | |
sb.append("\nlatitude : "); | |
sb.append(location.getLatitude()); | |
sb.append("\nlontitude : "); | |
sb.append(location.getLongitude()); | |
sb.append("\nradius : "); | |
sb.append(location.getRadius()); | |
mTvInfo.setText(sb.toString()); | |
mLocationClient.stop(); | |
} | |
@Override | |
public void onReceivePoi(BDLocation arg0) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment