2016-10-19 9 views
0

私はマップ活動を作成しました。私はクリックされたボタン上でマップアクティビティを呼び出します。それはエラーを示します。ここに私のコードは次のとおりです。 `map_icon.setOnClickListener(新OnClickListener(){クリックした画像上の地図アクティビティを開くには?

 @Override 
    public void onClick(View v) { 
    Intent i = new Intent(DepartmentUpdate_Detail.this, 
    MapActivity.class); 
    i.putExtra("lat", lat); 
    i.putExtra("lng", lng); 
    startActivity(i); 
    } 
    });` 

`

//と私のマップアクティビティは以下の通りです:

パブリッククラスMapActivityアクティビティがOnInfoWindowClickListener {

を実装して拡張します
private GoogleMap map; 

private int zoomLevel = 7; 

String latitude,longitude,address,city,country; 


protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.map_activity); 

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) 
    { 
     latitude = extras.getString("lat"); 
     longitude = extras.getString("lng"); 

    } 
    LatLng defaultLatLng = new LatLng(Double.valueOf(latitude), Double.valueOf(longitude)); 
    //Log.e("Latitude:Longitude",":"+Double.valueOf(latitude)+":"+ Double.valueOf(longitude)); 

    Geocoder geocoder; 
     List<Address> addresses; 
     geocoder = new Geocoder(this, Locale.getDefault()); 
     try { 
     addresses = geocoder.getFromLocation(Double.valueOf(latitude), Double.valueOf(longitude), 1); 
      address = addresses.get(0).getAddressLine(0); 
      city = addresses.get(0).getAddressLine(1); 
      country = addresses.get(0).getAddressLine(2); 

    } catch (NumberFormatException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    try { 

     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

     if (map!=null){ 

      map.getUiSettings().setCompassEnabled(true); 

      map.setTrafficEnabled(true); 

      map.setMyLocationEnabled(true); 

      // Move the camera instantly to defaultLatLng. 

      map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, zoomLevel)); 

      map.addMarker(new MarkerOptions().position(defaultLatLng) 

        .title("Location:") 

        .snippet(address+", "+city+", "+country) 

        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); 

      map.setOnInfoWindowClickListener(this); 
     } 

    } 
    catch (NullPointerException e) 
    { 
     e.printStackTrace(); 
    } 

} 

@Override 

public void onPause() { 

    if (map != null){ 
     map.setMyLocationEnabled(false); 
     map.setTrafficEnabled(false); 
    } 
    super.onPause(); 
} 

@Override 

public void onInfoWindowClick(Marker marker) { 
} 

} '

答えて

0

@Aks、あなたはonClickListenerをどこで宣言しましたか?これは、onCreate()メソッドで宣言して、アクティビティが拡張されると直ちにclickListenerをリッスンできるようにする必要があります。

0

だけのonClickメソッド内Uri.parseと、このコードでは、あなたのデータを入れ

Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia&mode=b"); 
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); 
mapIntent.setPackage("com.google.android.apps.maps"); 
startActivity(mapIntent); 
関連する問題