Monday, May 5, 2014

Android application development issues Baidu map location, novice seeking Great God help look


I am graduating students, work in the company, because the development needs, I went to study under the open platform Baidu Baidu Maps Map Android SDK location positioning function, and then I wrote a map to show your current location plus locate code. Why is my program, which is indeed the position of the positioning of the Pacific, rather than my current position, ah, then God help us to see where to find the big problem, the way to help me think about how can locate the point display "longitude latitude" and If I move a distance I could see the start position to the stop position trajectory. I am a beginner, it is best to explain the point code? Thank you
ps: all v.2.4.1 Android positioning Baidu Maps latest Android SDK Sdk
adoptedCode:
AndroidMainfest.xml

package = "com.blunt.demo"
android: versionCode = "1"
android: versionName = "1.0">
android: anyDensity = "true"
android: largeScreens = "true"
android: normalScreens = "true"
android: resizeable = "true"
android: smallScreens = "true" />

android: minSdkVersion = "14"
android: targetSdkVersion = "14" />
<-! Required permission to use network functions ->








<-! SDK offline map and write cache feature requires an external memory ->




<-! Get Set information and details page directly call phone needs the following permissions ->




<- Required permission to use positioning, demo integrated Baidu positioning SDK, can be removed without the use of targeting the following 6 -!>
















android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme">

android: name = "com.blunt.demo.MyMapActivity"
android: configChanges = "orientation | keyboardHidden"
android: label = "@ string / app_name"
android: screenOrientation = "sensor">







android: name = "com.baidu.lbsapi.API_KEY"
android: value = "secret key" />
android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote" />






Main Activity


public class MyMapActivity extends Activity

{
private static final String TAG = "TAG";

BMapManager mBMapMan = null;
MapView mMapView = null;

/ / Get site location information
private LocationClient locationClient = null;
private BDLocationListener bdLocationListener = new MyLocationListener ();

/ / Locate the current position

private MyLocationOverlay myLocationOverlay = null;
private LocationData locationData = null;

Handler mHandler = new Handler ()
{
public void handleMessage (android.os.Message msg)
{
Toast.makeText (getApplicationContext (), "msg:" + msg.what,
. Toast.LENGTH_SHORT) show ();
};
};

@ Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
mBMapMan = new BMapManager (getApplication ());
mBMapMan.init (null);

/ / Note: Please initialize BMapManager object before trial setContentView, otherwise it will error
setContentView (R.layout.activity_my_map);
mMapView = (MapView) findViewById (R.id.bmapsView);
mMapView.setBuiltInZoomControls (true);
/ / Set to enable the built-in zoom controls
MapController mMapController = mMapView.getController ();

locationClient = new LocationClient (getApplicationContext ());
locationClient.registerLocationListener (bdLocationListener);

LocationClientOption option = new LocationClientOption ();
option.setOpenGps (true); / / whether to open GPRS
option.setAddrType ("all") ;/ / positioning results returned contain address information
option.setCoorType ("bd09ll") ;/ / positioning results returned is Baidu latitude and longitude, the default value gcj02
option.setScanSpan (50000) ;/ / set the interval to initiate positioning request to 5000ms
option.disableCache (true) ;/ / enable caching positioning
banoption.setPoiNumber (5); / / returns the maximum number of
POIoption.setPoiDistance (1000); / / poi inquiries from
option.setPriority (LocationClientOption.NetWorkFirst);
locationClient.setLocOption (option);
locationClient.start ();
if (locationClient! = null && locationClient.isStarted ())
{
locationClient.requestLocation ();
locationClient.requestPoi ();
} Else
{
Log.d (TAG, "locClient is null or not started");
}

mMapController.setZoom (12) ;/ / set the map zoom level

myLocationOverlay = new MyLocationOverlay (mMapView);
locationData = new LocationData ();
myLocationOverlay.setData (locationData);
mMapView.getOverlays () add (myLocationOverlay);.
myLocationOverlay.enableCompass ();
mMapView.refresh ();

}




@ Override
protected void onStop ()
{
locationClient.stop ();
super.onStop ();
}

@ Override
protected void onDestroy ()
{

mMapView.destroy ();
locationClient.unRegisterLocationListener (bdLocationListener);

if (mBMapMan! = null)
{
mBMapMan.destroy ();
mBMapMan = null;
}
locationClient.stop ();
myLocationOverlay.disableCompass ();
myLocationOverlay = null;
mMapView = null;
locationClient = null;
locationData = null;
super.onDestroy ();
}

@ Override
protected void onPause ()
{

mMapView.onPause ();
if (mBMapMan! = null)
{
mBMapMan.stop ();
}
locationClient.stop ();

super.onPause ();
}

@ Override
protected void onResume ()
{

mMapView.onResume ();
if (mBMapMan! = null)
{
mBMapMan.start ();
}
locationClient.start ();
super.onResume ();
}

private class MyLocationListener implements BDLocationListener
{

@ Override
public void onReceiveLocation (BDLocation location)
{
/ / Log.v (TAG,
/ / "OnReceiveLocation ---> getLatitude --->" + String.valueOf (position.getLatitude ()))
/ /;
/ / Log.v (TAG,
/ / "OnReceiveLocation ---> getLocType --->" + String.valueOf (position.getLongitude ()))
/ /;
/ / Log.v (TAG,
/ / "OnReceiveLocation ---> getRadius --->" + String.valueOf (position.getRadius ()))
/ /;
/ / Log.v (TAG,
/ / "OnReceiveLocation ---> position --->" + String.valueOf (position.getAddrStr ()))
/ /;

locationData.latitude = location.getLatitude ();
locationData.longitude = location.getLongitude ();
locationData.accuracy = location.getRadius ();
locationData.direction = location.getDerect ();
myLocationOverlay.setData (locationData);
mMapView.refresh ();
mMapView.getController (). animateTo (
new GeoPoint ((int) (locationData.latitude * 1e6),
(Int) (locationData.longitude * 1e6)),
mHandler.obtainMessage (1));

}

@ Override
public void onReceivePoi (BDLocation location)
{
locationData.latitude = location.getLatitude ();

locationData.longitude = location.getLongitude ();

}

}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Position offset is too large, then consider whether or not to engage in bad latitude and longitude
Reply:
I considered this reason, did not write bad ah

Reply:
Click to get MyLocationListener inside debug precision latitude, see if it is the correct value, whether the positioning, whether to get into the accuracy of latitude

No comments:

Post a Comment