Sunday, January 10, 2016

About android Baidu map api unable to locate,




            


According to code-demo, demo can locate, but can 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
 
& Lt;? Xml version = "1.0" encoding = "utf-8" & gt;?
& Lt; manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "com.dragonmuou.gowhere"
android: versionCode = "1"
android: versionName = "1.0" & gt;

& Lt; uses-sdk
android: minSdkVersion = "8"
android: targetSdkVersion = "10" / & gt;

& Lt; application
android: name = "GowhereApplication"
android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme" & gt;
& Lt; activity
android: name = "LoginActivity"
android: configChanges = "orientation | keyboardHidden"
android: label = "@ string / app_name"
android: screenOrientation = "sensor" & gt;
& Lt; intent-filter & gt;
& Lt; action android: name = "android.intent.action.MAIN" / & gt;

& Lt; category android: name = "android.intent.category.LAUNCHER" / & gt;
& Lt; / intent-filter & gt;
& Lt; / activity & gt;
& Lt; activity
android: name = "FriendsActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor" & gt;
& Lt; / activity & gt;
& Lt; activity
android: name = "GomapActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor" & gt;
& Lt; / activity & gt;
& Lt; activity
android: name = "MainActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor" & gt;
& Lt; / activity & gt;
& Lt; activity
android: name = "RecallActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor" & gt;
& Lt; / activity & gt;
& Lt; activity
android: name = "SetupActivity"
android: configChanges = "orientation | keyboardHidden"
android: screenOrientation = "sensor" & gt;
& Lt; / activity & gt;

& Lt; service
android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote" & gt;
& Lt; / service & gt;
& Lt; / application & gt;
& Lt; uses-permission android: name = "android.permission.ACCESS_NETWORK_STATE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.INTERNET" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.ACCESS_WIFI_STATE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.CHANGE_WIFI_STATE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.READ_PHONE_STATE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.CALL_PHONE" & gt; & lt; / uses-permission & gt;
& Lt; permission android: name = "android.permission.BAIDU_LOCATION_SERVICE" & gt; & lt; / permission & gt;
& Lt; uses-permission android: name = "android.permission.BAIDU_LOCATION_SERVICE" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.ACCES_MOCK_LOCATION" & gt; & lt; / uses-permission & gt;
& Lt; uses-permission android: name = "android.permission.ACCESS_GPS" / & gt;

& Lt; / manifest & gt;

According onReceiveLocation log display is not performed, and 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 change to your code location
between; super.onCreate (savedInstanceState); and setContentView (R.layout.activity_gomap)
Reply:
Plus
in AndroidManifest.xml file& Lt; application & gt;
& Lt; activity & gt; & lt; / activity & gt;
....

& Lt; service
android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote" & gt;
& Lt; / service & gt;
& Lt; / application & gt;

It
Reply:
The landlord, the problem solved? I also encountered the same problem, seek the guidance
Reply:
I also encountered the same problem, seek the guidance
Reply:
locationClient.start (); followed by locationClient.requestLocation (); initiate positioning
Reply:
I also met today, ask the landlord to solve it, ah, how to solve
?
Reply:
quote 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 () Gets the main program of the context, rather than a single activity of the context, you can locate the
Reply:
Thank you, the landlord ah, the same problem, with the landlord to give a solution to the 8th floor,
I do not know why? Why not a single Activity of Context. To getApplicationContext () just fine
Reply:
I was confused for a long time, finally realized, really appreciate
Reply:
Well, I learn. . same question
Reply:
quote 3rd floor ayb0473 reply:


Brother, thank you very much!
Reply:
quote 3rd floor ayb0473 reply:
add
in AndroidManifest.xml file& Lt; application & gt;
& Lt; activity & gt; & lt; / activity & gt;
....

& Lt; service
android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote" & gt;
& Lt; / service & gt;
& Lt; / application & gt;

It
add this on it, it took several hours to solve this problem, very grateful to the brothers ,
Reply:
Tier 3 plus 8 floor building, showing successful positioning
Reply:
Finally resolved, with 14 floors, with a 3-floor building +8 method of locating a success
Reply:

Reply:
The question that bothers me two days, finally resolved, thank landlord
Reply:
I am troubled half-day finally solved the problem
Reply:
quote 3rd floor ayb0473 reply:
add
in AndroidManifest.xml file& Lt; application & gt;
& Lt; activity & gt; & lt; / activity & gt;
....

& Lt; service
android: name = "com.baidu.location.f"
android: enabled = "true"
android: process = ": remote" & gt;
& Lt; / service & gt;
& Lt; / application & gt;

It


Thank +1 Mody Mody da ~~~! ! ! Very, very grateful ~
Reply:
Plus the 8th floor 3rd floor general solution method
Reply:
Thank lz great
Reply:
Really grateful to find this problem one morning, the 8th floor perfect solution
Reply:
+12 8 House floor

getApplicationContext ()
+
mainfest service
okey !!!!

Thanks
Reply:
Thank you very much, my problem solved.
Reply:
Overall feeling Baidu Maps API developer documentation is not written very good, hope that they can be written for each function a separate demo, demo and not all write together. I do not want to develop a re-encounter new things we should study a waste of time.
Reply:
After the remote location, there is no regularly issues a message to locate the ah? I just move on how to locate the post?
Reply:
Printed locClient.start () method has been false, simply can not be listening to events with a remote service to load positioning, then, start method can not continue to load
Reply:
Grateful ah, Shetenglebantian not ready, ok! ! !
+12 8 House floor

getApplicationContext ()
+
mainfest service
Reply:
On the third floor of nice, thank you brothers
Reply:
Finally resolved, with the 14th floor, with a 3-floor building +8 method of locating a success
Reply:
Why only I did not fix it?
Reply:
thanks
Reply:
Extremely grateful, the issue is resolved. With the 14th floor, with a 3-floor building +8 method of locating a success
Reply:
Similarly
getApplicationContext ()
+
mainfest service

thank!
Reply:
We must examine the next demo .so file inside the 3rd floor +8 floor yet achieved whether to add to their project the inside, there are not less .so file jar package, I get a few days, and finally found a less .so files, finally solved the problem, let me thank everyone's participation to solve the problem
Reply:
Extremely grateful, the issue is resolved.

No comments:

Post a Comment