2013-03-17 48 views
0

我正在構建一個應用程序,允許用戶通過選擇標記並單擊信息窗口來確認接近警報。我需要能夠從標記中獲取經度和緯度,以便我可以使用座標來設置半徑。獲取標記座標傳遞給變量

googleMap.setOnInfoWindowClickListener(
    new OnInfoWindowClickListener(){ 
    public void onInfoWindowClick(Marker marker) { 

     //click function 
     Toast.makeText(getBaseContext(), 
     "Info Window [email protected]" + marker.getPosition(), 
     Toast.LENGTH_SHORT).show(); 

    LocationManager lm; 
    double lat=0; 
    double long1=0; //Defining Latitude & Longitude 
    float radius=3000; 

    lm=(LocationManager) getSystemService(LOCATION_SERVICE); 
    Intent i= new Intent("com.example.sleepertrain5.proximityalert");   //Custom Action 
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), -1, i, 0); 
    lm.addProximityAlert(lat, long1, radius, -1, pi); 

到目前爲止,我只能夠找到marker.getLocation()不允許直接變量設置。有沒有辦法做到這一點?

回答

0

你有沒有嘗試過這樣的:

map.setInfoWindowAdapter(new InfoWindowAdapter() { 

// Use default InfoWindow frame 
@Override 
public View getInfoWindow(Marker args) { 
    return null; 
} 

// Defines the contents of the InfoWindow 
@Override 
public View getInfoContents(Marker args) 
{ 
    LatLng clickedMarkerLatLng = args.getPosition(); 
    double latitude = clickedMarkerLatLng.latitude; 
    double longitude = clickedMarkerLatLng.longitude; 
    .... 
} 
0

我希望這個代碼可以幫助你:

@Override 
public void onMapLongClick(LatLng point) { 

Latitude lat = point.getLatitude(); 
Longitude lng = point.getLongitude(); 

} 
相關問題