2011-01-10 8 views
1

私は本当にこの上で立ち往生していますに経度/緯度の存在を計算する方法:現在のビュー

私はAndroidアプリでGoogleマップ上に描画するための経度/緯度ポイントを持っています。 そのため私は介してビューの現在の経度/緯度の部分を取得...

オーバーレイを拡張するクラスを作成した:

GeoPoint topLeft = proj.fromPixels(0, 0); 
GeoPoint bottomRight = proj.fromPixels(width-1, height-1); 
int topLat = topLeft.getLatitudeE6(); 
int topLon = topLeft.getLongitudeE6(); 
int bottomLat = bottomRight.getLatitudeE6(); 
int bottomLon = bottomRight.getLongitudeE6(); 

次の作品(のみ緯度):

if(latLon[0] >= bottomLat && latLon[0] <= topLat){ // do something; } 

をけれどもこれは機能しません(経度):

if(latLon[1] >= topLon && latLon[1] <= bottomLon) { // do something; } 

latLon [0]はl atitude私はチェックしたい latLon [1]は確認したい経度です

誰かアイデア?

Greetz!

答えて

0

緯度番号は、イギリス西部の0子午線からマイナスです。彼らは北米と南米ではマイナスです。

+0

@ n3bul4したがって、あなたのtopLon、または最大経度、またはほとんどの東経は画面の右側にあります。左には書いたとおりではありません。 – NickT

0

Googleマップを使用してマーカーを挿入します。 以下参照:

public class MapActivity extends GeolocationActivity implements GoogleMap.OnInfoWindowClickListener{ 

private final String TAG = "MapFragment"; 


private MapView _mapView; 
private GoogleMap _gmap; 

/** 
* the logo of the marker on the map 
*/ 
private Bitmap _littlePin; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.map); 

    _mapView = (MapView) findViewById(R.id.location_map); 
    _mapView.onCreate(savedInstanceState); 
    _gmap = _mapView.getMap(); // initalise the map 
    if (_gmap != null) 
    { 
     setUpMap(); 
    } 
} 

/** 
* set up the map; Add the market on it with a blue dot for the location of the user in real time 
* @return false if something goes wrong, true otherwise 
* _latitude = latitude of the user, get from the GeolocationActivity 
* _longitude = longitude of the user, get from the GeolocationActivity 
*/ 
private boolean setUpMap() 
{ 
    // Gets to GoogleMap from the MapView and does initialization stuff 
    _gmap.getUiSettings().setMyLocationButtonEnabled(false); 
    _gmap.setMyLocationEnabled(true); 
    if (_gmap == null) { 
     Toast.makeText(this, "Google Maps not available", Toast.LENGTH_LONG).show(); 
     return false; 
    } 
    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls 
    MapsInitializer.initialize(this); 


    BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.pin); // file stored in /res/drawable/ 
    Bitmap bitmap = bitmapDrawable.getBitmap(); 
    _littlePin = Bitmap.createScaledBitmap(bitmap, 96, 96, false); // 96/96px 

    _gmap.setOnInfoWindowClickListener(this);// add listener on this class 


    // here the _lat and _long should be the user of this cafe, at the moment I am using the one of the user 
    this.addMarker("Cafe", "Best cafe in London", new LatLng(_latitude, _longitude)); 


    // camera, 13 if the zoon, you can change it manually, or dynamically in order to see all your markers 
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(_latitude, _longitude), 13); 
    _gmap.animateCamera(cameraUpdate); // zoom effect 
    return true; 
} 

/** 
* Add markers on the map view 
* @param title title of place/marker 
* @param description short description 
* @param position geposition, LatLng object, filled with latitude and longitude. 
*/ 
private void addMarker(String title, String description, LatLng position) 
{ 
    _gmap.addMarker(new MarkerOptions() 
      .position(position) 
      .title(title) 
      .snippet(description) 
      .icon(BitmapDescriptorFactory.fromBitmap(_littlePin))); 
} 

/** 
* The user click on the marker on the map, this callback is called 
* @param marker clicked marker 
*/ 
@Override 
public void onInfoWindowClick(Marker marker) { 
    Log.d(TAG, "onMarkerClick " + marker.getTitle()); 
} 


@Override 
public void onResume() { 
    _mapView.onResume(); 
    super.onResume(); 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    _mapView.onDestroy(); 
} 

@Override 
public void onLowMemory() { 
    super.onLowMemory(); 
    _mapView.onLowMemory(); 
} 

}

Here is a good example which gonna help you.

code sample is hereとgithubの。

このヘルプが必要です。

関連する問題