【Android(谷歌地图标记)】一年好景君须记,最是橙黄橘绿时。这篇文章主要讲述Android:谷歌地图标记相关的知识,希望能为你提供帮助。
This is part of a much larger class but I wanted to give enough context to explain the value of GeoCoder. GeoCoder has two methods called getFromLocation() and getFromLocationName() that allow you to capture an address or coordinates.
- /**********************************
- * Fired every time a user touches the map
- * MotionEvent.getAction() lets you determine
- *whether a user has lifted their finger
- **********************************/
- @Override
- public boolean onTouchEvent( MotionEvent e, MapView mapView) {
- if( e.getAction( ) == 1 ) {
- //getProjection() returns screen-pixel coords to lat/lng coordinates
- //fromPixels converts the screen coordinates into a GeoPoint
- GeoPoint geoPoint = mapView.getProjection( ) .fromPixels(
- ( int) e.getX( ) ,
- ( int) e.getY( ) ) ;
- /*
- Toast.makeText( getActivity(),
- " Location: " + geoPoint.getLatitudeE6() / 1E6 + " , " +
- geoPoint.getLongitudeE6() / 1E6,
- Toast.LENGTH_SHORT).show();
- */
- //Geocoder converts lat/lng into an address
- Geocoder geocoder = new Geocoder( getActivity( ) , Locale.getDefault( ) ) ;
- try{
- //getFromLocation() does the reverse Geo Location
- List< Address> addresses = geocoder.getFromLocation(
- geoPoint.getLatitudeE6( ) / 1E6,
- geoPoint.getLongitudeE6( ) / 1E6,
- 1 ) ;
- //Capture the address in a String
- String addy = " " ;
- if( addresses.size( ) > 0 ) {
- for ( int i = 0; i < addresses.get( 0) .getMaxAddressLineIndex( ) ; i++ ) {
- addy += addresses.get( 0) .getAddressLine( i) + " " ;
- }
- }
- //Present the address using Toast
- Toast.makeText( getActivity( ) , addy, Toast.LENGTH_SHORT) .show( ) ;
- }
- catch( IOException evt ) {
- evt.printStackTrace( ) ;
- }
- /**********************************
- * Find the Geo Coordinates based on the Name
- **********************************/
- try{
- List< Address> addresses = geocoder.getFromLocationName( " kusc" , 5) ;
- String addy = " " ;
- if( addresses.size( ) > 0 ) {
- geoPoint = new GeoPoint(
- ( int) ( addresses.get( 0) .getLatitude( ) * 1E6) ,
- ( int) ( addresses.get( 0) .getLongitude( ) * 1E6) ) ;
- mapController.animateTo( geoPoint) ;
- mapView.invalidate( ) ;
- }
- //Present the address using Toast
- Toast.makeText( getActivity( ) , addy, Toast.LENGTH_SHORT) .show( ) ;
- } catch( IOException evt) {
- evt.printStackTrace( ) ;
- }
- }
- //onTouchEvent requires a boolean
- return false;
- }
- }
推荐阅读
- 在android中拥有sqlite数据库
- Android(以编程方式删除标题/通知栏)
- 将Apple.plist文件从XML/binary转换为
- Android简单警报
- PhoneGap项目的Android元视口标记
- 一键构建PhoneGap构建到Android
- Android检查服务是否正在运行
- 钛Appcelerator zipfile模块(适用于1.8的提取方法)
- Favicon和Apple Touch图标