Monday, January 20, 2014

Baidu map api on android can not locate,


            
Carried out in accordance with demo code, demo can be positioned, but could not locate my,
 
package com.dragonmuou.gowhere;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapViewListener;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.FrameLayout;
import android.widget.Toast;

public class GomapActivity extends Activity {

private MapView mMapView = null;
private MapController mMapController = null;
FrameLayout mMapViewContainer = null;
MKMapViewListener mMapListener = null;

MyLocationOverlay myLocationOverlay = null;
LocationData locData = null;
LocationClient locClient;
MyLocationListenner mylisten = new MyLocationListenner ();

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_gomap);
/ / GowhereApplication app = (GowhereApplication) this.getApplication ();

/ / If (app.mBMapManager == null) {
/ / App.mBMapManager = new BMapManager (this);
/ / App.mBMapManager.init (GowhereApplication.strKey,
/ / New GowhereApplication.MyGeneralListener ());
/ / App.mBMapManager.start ();
/ /
/ /}
mMapView = (MapView) findViewById (R.id.bmapsView);
mMapController = mMapView.getController ();
initMapView ();

locClient = new LocationClient (this);
locClient.registerLocationListener (mylisten);
LocationClientOption option = new LocationClientOption ();
option.setOpenGps (true) ;/ / open gps
option.setCoorType ("bd09ll"); / / set the coordinate type
option.setScanSpan (1000);
locClient.setLocOption (option);

locClient.start ();


locData = new LocationData ();

. mMapView.getController () setZoom (14);
mMapView.getController () enableClick (true);.
/ / MMapView.setTraffic (true);
mMapView.setDoubleClickZooming (true);
mMapView.setBuiltInZoomControls (true);
mMapView.setOnLongClickListener (new MyLongClickable ());

mMapListener = new MKMapViewListener () {
@ Override
public void onMapMoveFinish () {
/ / TODO Auto-generated method stub

}

@ Override
public void onClickMapPoi (MapPoi arg0) {
/ / TODO Auto-generated method stub
String title = "";
if (arg0! = null) {
title = arg0.strText;
Toast.makeText (GomapActivity.this, title, Toast.LENGTH_LONG)
. Show ();
mMapController.animateTo (arg0.geoPt);
}
}
};

mMapView.regMapViewListener (
GowhereApplication.getInstance () mBMapManager, mMapListener);.

myLocationOverlay = new MyLocationOverlay (mMapView);
myLocationOverlay.enableCompass ();
/ / Log.v ("locData", locData.latitude + "" + locData.longitude);
mMapView.getOverlays () add (myLocationOverlay);.
/ / MyLocationOverlay.setData (locData);
mMapView.refresh ();
/ / LocClient.requestLocation ();


}

class MyLongClickable implements OnLongClickListener {

@ Override
public boolean onLongClick (View v) {
/ / TODO Auto-generated method stub
/ / Dialog dialog = new Dialog (GomapActivity.this);
/ / Window window = dialog.getWindow ();
/ / Window.setLayout (50, 100);
/ / Dialog.show ();
return false;
}

}

public class MyLocationListenner implements BDLocationListener {

@ Override
public void onReceiveLocation (BDLocation location) {
/ / TODO Auto-generated method stub
if (location == null) {
Log.v ("locData", "null");
return;
}

locData.latitude = location.getLatitude ();
locData.longitude = location.getLongitude ();
locData.direction = 2.0f;
locData.accuracy = location.getRadius ();
locData.direction = location.getDerect ();
myLocationOverlay.setData (locData);
Log.v ("locData", "onReceiveLocation" + locData.latitude + "" + locData.longitude);
mMapController.setCenter (new GeoPoint ((int) (locData.latitude * 1e6), (int) (locData.longitude * 1e6)));
mMapView.refresh ();

}

@ Override
public void onReceivePoi (BDLocation arg0) {
/ / TODO Auto-generated method stub
if (arg0 == null)
return;
}

}

private void initMapView () {
GeoPoint centerpt = mMapView.getMapCenter ();
int maxLevel = mMapView.getMaxZoomLevel ();
int zoomlevel = mMapView.getZoomLevel ();
boolean isTraffic = mMapView.isTraffic ();
boolean isSatillite = mMapView.isSatellite ();
boolean isDoubleClick = mMapView.isDoubleClickZooming ();
mMapView.setLongClickable (true);

/ / MMapController.setMapClickEnable (true);
/ / MMapView.setSatellite (false);
}

@ Override
protected void onDestroy () {
/ / TODO Auto-generated method stub
mMapView.destroy ();
super.onDestroy ();

}

@ Override
protected void onPause () {
/ / TODO Auto-generated method stub
mMapView.onPause ();
super.onPause ();

}

@ Override
protected void onResume () {
/ / TODO Auto-generated method stub
mMapView.onResume ();
super.onResume ();
}

@ Override
protected void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState (outState);
mMapView.onSaveInstanceState (outState);

}

@ Override
protected void onRestoreInstanceState (Bundle savedInstanceState) {
super.onRestoreInstanceState (savedInstanceState);
mMapView.onRestoreInstanceState (savedInstanceState);
}

@ Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged (newConfig);
}

}



This is the configuration file
 

package = "com.dragonmuou.gowhere"
android: versionCode = "1"
android: versionName = "1.0">

android: minSdkVersion = "8"
android: targetSdkVersion = "10" />

android: name = "GowhereApplication"
android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme">
android: name = "LoginActivity"
android: configChanges = "orientation | keyboardHidden"
android: label = "@ string / app_name"
android: screenOrientation = "sensor">






android: name = "FriendsActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor">

android: name = "GomapActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor">

android: name = "MainActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor">

android: name = "RecallActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor">

android: name = "SetupActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor">


android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote">


















According log display onReceiveLocation not running, who knows, oh, seeking ah

Reply:
I also encountered the same problem, seek expert advice
Reply:
if (app.mBMapManager == null) {
/ / App.mBMapManager = new BMapManager (this);
/ / App.mBMapManager.init (GowhereApplication.strKey,
/ / New GowhereApplication.MyGeneralListener ());
/ / App.mBMapManager.start ();
/ /
/ /}

The above changes to your code location
between; super.onCreate (savedInstanceState); and setContentView (R.layout.activity_gomap)
Reply:
Plus
in AndroidManifest.xml file

....

android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote">



On it
Reply:
Landlord, problem solved? I also encountered the same problem, seeking advice
Reply:
I also encountered the same problem, seeking advice
Reply:
locationClient.start (); followed by locationClient.requestLocation (); initiated positioning
Reply:
I also met today, ask the landlord to solve it, ah, how to solve
?
Reply:
reference to the 7th floor f330656066 reply:
I also met today,
ask the landlord to solve it, ah, how to solve?

Ah, to solve the locClient = new LocationClient (getApplicationContext ()); use getApplicationContext () to get the main program context, rather than a single activity in context, you can locate the
Reply:
Thank you, landlord ah, the same problem with the landlord to give a solution to the 8th floor,
I do not know why? Single Activity in Context why not. To getApplicationContext () just fine
Reply:
I puzzled for a long time, finally realized, sincerely thank
Reply:
Well, learn. . The same problem
Reply:
reference to the third floor ayb0473 reply:


Brother, thank you very much!
Reply:
reference to the third floor ayb0473 reply:
plus
in AndroidManifest.xml file

....

android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote">



On it
add this can be, it took several hours to solve this problem, very grateful to the brothers ,

No comments:

Post a Comment