Monday, March 3, 2014

 According to the latitude and longitude to find the address information (call android map Baidu API)


With com.baidu.mapapi.map correlation function
According to the latitude and longitude to find the address information (call android map Baidu API)
For example: Given a coordinate GeoPoint mylocation = new GeoPoint ((int) (29.855 * 1E6),
(Int) (114.345 * 1E6)) ;/ /
Is there any way you can get the coordinates of the corresponding address information? Seek expert help! Thank you la la la!
To address the information given in great detail, can be as small to a building, such as "Baidu building." Seeking advice,
Jiji Ji! Online ......<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
GeoPoint mylocation = new GeoPoint ((int) (29.855 * 1E6),
(Int) (114.345 * 1E6));
Search.reverseGeocode (mylocation);

Return result in MKSearchListener notification method in the onGetAddrResult
Reply:
Upstairs: The ah, not detailed enough, can only be to an area to a building can not
!
package hu.sheng.jin;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.BDNotifyListener;
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.mapapi.search.MKAddrInfo;
import com.baidu.mapapi.search.MKBusLineResult;
import com.baidu.mapapi.search.MKDrivingRouteResult;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.mapapi.search.MKSearch;
import com.baidu.mapapi.search.MKSearchListener;
import com.baidu.mapapi.search.MKSuggestionResult;
import com.baidu.mapapi.search.MKTransitRouteResult;
import com.baidu.mapapi.search.MKWalkingRouteResult;
import com.baidu.platform.comapi.basestruct.GeoPoint;

public class LocationOverlayDemo extends Activity {
static GeoPoint mylocation = new GeoPoint ((int) (29.855 * 1E6),
(Int) (114.345 * 1E6)) ;/ / if you do not give me the position, then default to the Hubei Institute of Technology Library
static MapView mMapView = null;
private MapController mMapController = null;
public MKMapViewListener mMapListener = null;
FrameLayout mMapViewContainer = null;
/ / Locate relevant
LocationClient mLocClient;
public MyLocationListenner myListener = new MyLocationListenner ();
public NotifyLister mNotifyer = null;
Button testUpdateButton = null;
Button NearbyButton = null;
Button locationname = null;
EditText indexText = null;
MyLocationOverlay myLocationOverlay = null;
int index = 0;
static String nowlocatoinname = null;
LocationData locData = null;
DemoApplication app;
Handler mHandler = new Handler () {
public void handleMessage (android.os.Message msg) {
Toast.makeText (LocationOverlayDemo.this, "positioning success!", Toast.LENGTH_SHORT)
. Show ();
};
};

@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
app = (DemoApplication) this.getApplication ();
if (app.mBMapManager == null) {
app.mBMapManager = new BMapManager (this);
app.mBMapManager.init (DemoApplication.strKey,
new DemoApplication.MyGeneralListener ());
}
setContentView (R.layout.activity_locationoverlay);
mMapView = (MapView) findViewById (R.id.bmapView);
mMapController = mMapView.getController ();

initMapView ();

mLocClient = new LocationClient (this);
mLocClient.registerLocationListener (myListener);

LocationClientOption option = new LocationClientOption ();
option.setOpenGps (true) ;/ / open gps
option.setCoorType ("bd09ll"); / / set the coordinate type
/ / Option.setScanSpan (1000); / / 1 second scan
mLocClient.setLocOption (option);
mLocClient.start ();
. mMapView.getController () setZoom (17);
mMapView.getController () enableClick (true);.

mMapView.setBuiltInZoomControls (true);
mMapListener = new MKMapViewListener () {

@ Override
public void onMapMoveFinish () {
/ / TODO Auto-generated method stub
}

@ Override
public void onClickMapPoi (MapPoi mapPoiInfo) {
/ / TODO Auto-generated method stub
String title = "";
if (mapPoiInfo! = null) {
title = mapPoiInfo.strText;
mylocation = mapPoiInfo.geoPt ;/ / modify the coordinates
Toast.makeText (LocationOverlayDemo.this, title,
. Toast.LENGTH_SHORT) show ();
}
}

@ Override
public void onGetCurrentMap (Bitmap b) {
/ / TODO Auto-generated method stub
}

@ Override
public void onMapAnimationFinish () {
/ / TODO Auto-generated method stub

}
};
mMapView.regMapViewListener (DemoApplication.getInstance (). mBMapManager,
mMapListener);
myLocationOverlay = new MyLocationOverlay (mMapView);
locData = new LocationData ();
myLocationOverlay.setData (locData);
mMapView.getOverlays () add (myLocationOverlay);.
myLocationOverlay.enableCompass ();
mMapView.refresh ();

testUpdateButton = (Button) findViewById (R.id.button1);
OnClickListener clickListener = new OnClickListener () {
public void onClick (View v) {
testUpdateClick ();
}
};
testUpdateButton.setOnClickListener (clickListener);

NearbyButton = (Button) findViewById (R.id.button2);
OnClickListener clickListener1 = new OnClickListener () {
public void onClick (View v) {
NearbySearch ();
}
};
NearbyButton.setOnClickListener (clickListener1);


locationname = (Button) findViewById (R.id.button3);

}

protected void NearbySearch () {
/ / TODO Auto-generated method stub
Intent intent = new Intent ();
intent.setClass (LocationOverlayDemo.this, NearbyPoiSearch.class);
this.startActivity (intent);
}

@ Override
protected void onPause () {
mMapView.onPause ();
super.onPause ();
}

@ Override
protected void onResume () {
mMapView.onResume ();
super.onResume ();
}

@ Override
protected void onDestroy () {
if (mLocClient! = null)
mLocClient.stop ();
mMapView.destroy ();
DemoApplication app = (DemoApplication) this.getApplication ();
if (app.mBMapManager! = null) {
app.mBMapManager.destroy ();
app.mBMapManager = null;
}
super.onDestroy ();
}

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

}

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

public void testUpdateClick () {
mLocClient.requestLocation ();
}

private void initMapView () {
mMapView.setLongClickable (true);
/ / MMapController.setMapClickEnable (true);
/ / MMapView.setSatellite (false);
}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater () inflate (R.menu.activity_main, menu);.
return true;
}

/ **
* Monitor function, and the new location when a string formatted output to the screen
* /
public class MyLocationListenner implements BDLocationListener {
@ Override
public void onReceiveLocation (BDLocation location) {
if (location == null)
return;
locData.latitude = location.getLatitude ();
locData.longitude = location.getLongitude ();
locData.accuracy = location.getRadius ();
locData.direction = location.getDerect ();
myLocationOverlay.setData (locData);
mMapView.refresh ();
mylocation = new GeoPoint ((int) (locData.latitude * 1e6),
(Int) (locData.longitude * 1e6));

MapPoi mapPoiInfo = null;

MKSearch mks = new MKSearch ();
mks.reverseGeocode (mylocation);
mks.init (app.mBMapManager, new MKSearchListener () {
@ Override
public void onGetPoiDetailSearchResult (int type, int error) {
}
public void onGetAddrResult (MKAddrInfo res, int error) {
if (error! = 0) {
String str = String.format ("Error number:% d", error);
Toast.makeText (LocationOverlayDemo.this, str,
. Toast.LENGTH_LONG) show ();
return;
}
nowlocatoinname = res.strAddr;
locationname.setText ("you" + nowlocatoinname);
}

@ Override
public void onGetBusDetailResult (MKBusLineResult arg0, int arg1) {
/ / TODO Auto-generated method stub
}
@ Override
public void onGetDrivingRouteResult (MKDrivingRouteResult arg0,
int arg1) {

}

@ Override
public void onGetPoiResult (MKPoiResult arg0, int arg1, int arg2) {
}

@ Override
public void onGetSuggestionResult (MKSuggestionResult arg0,
int arg1) {
/ / TODO Auto-generated method stub

}

@ Override
public void onGetTransitRouteResult (MKTransitRouteResult arg0,
int arg1) {
/ / TODO Auto-generated method stub

}

@ Override
public void onGetWalkingRouteResult (MKWalkingRouteResult arg0,
int arg1) {
/ / TODO Auto-generated method stub

}
});

mMapController.animateTo (mylocation, mHandler.obtainMessage (1));
}

public void onReceivePoi (BDLocation poiLocation) {
if (poiLocation == null) {
return;
}
}

}

public class NotifyLister extends BDNotifyListener {
public void onNotify (BDLocation mlocation, float distance) {
}
}

}

Reply:
public void onGetAddrResult (MKAddrInfo res, int error) {
if (error! = 0) {
String str = String.format ("Error number:% d", error);
Toast.makeText (LocationOverlayDemo.this, str,
. Toast.LENGTH_LONG) show ();
return;
}
Your function is to address the res is the detailed information
Reply:
Upstairs Hello: This function can indeed get an address, but it is here to break out of the address Haman District Xianning City s208, I hope that the effect of Xianning Xianning City Haman District Road No. 88, Hubei Science and Technology College Library;

(2) When we click on the map when it will trigger
public void onClickMapPoi (MapPoi mapPoiInfo) {
/ / TODO Auto-generated method stub
String title = "";
if (mapPoiInfo! = null) {
title = mapPoiInfo.strText;
mylocation = mapPoiInfo.geoPt ;/ / modify the coordinates
Toast.makeText (LocationOverlayDemo.this, title,
. Toast.LENGTH_SHORT) show ();
}
This function can print out a very small place, such as Hubei Academy of Sciences Library; I want is this news, I hope I'll locate the position after a successful center of the map is automatically printed out, rather than after I click Print
Reply:
By
public void onGetAddrResult (MKAddrInfo res, int error) {
if (error! = 0) {
String str = String.format ("Error number:% d", error);
Toast.makeText (LocationOverlayDemo.this, str,
. Toast.LENGTH_LONG) show ();
return;
}
In fact, check out the route, I want a specific coordinate point, seeking advice ah
Reply:
The landlord did not solve the problem ah? Recently, I have been troubled by this issue, is obtained after Geocoder or by using latitude and longitude to visit Baidu homepage return address always have error ah! Is about 500 to 600 error! Can not pinpoint ah! Landlord seeking to rescue ah!

No comments:

Post a Comment