0

我已经在谷歌地图上使用mapView api2 android中的应用程序,我已经尝试了下面的code.map是runnig完全但我想它时,点击片段,然后特别“url “应该在secondActivity的webview中加载。我的代码如下:MApView不显示在android中使用谷歌api v2

Main.java

package com.example.mapviewdemo; 

import java.security.PublicKey; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.webkit.WebView; 
import android.widget.Toast; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener; 
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.UiSettings; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends FragmentActivity { 
    private GoogleMap map; 
    WebView wv; 
private String a ; 
private String b ; 
//public String ah="http://en.wikipedia.org/wiki/Ahmedabad"; 
//public String br="http://en.wikipedia.org/wiki/Baroda"; 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     map = ((SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map)).getMap(); 
     setUpMap(); 
     if (map != null) { 
     Marker Ahmedabad = map.addMarker(new MarkerOptions().position(
        new LatLng(Double.parseDouble("23.03957"), Double 
          .parseDouble("72.56600"))).title("Ahmedabad")); 
      Marker Baroda = map.addMarker(new MarkerOptions() 
        .position(
          new LatLng(Double.parseDouble("22.30731"), Double 
            .parseDouble("73.18110"))) 
        .title("Baroda") 
        .snippet("Baroda") 
        .icon(BitmapDescriptorFactory 
          .fromResource(R.drawable.pin_blue))); 

      // Move the camera instantly to hamburg with a zoom of 15. 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(
        new LatLng(Double.parseDouble("23.03957"), Double 
          .parseDouble("72.56600")), 15)); 

      // Zoom in, animating the camera. 
      map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 
      a =Ahmedabad.getTitle(); 
      b = Baroda.getTitle(); 
     } 
    } 
    private void setUpMap() { 

     UiSettings setting = map.getUiSettings(); 
     setting.setMyLocationButtonEnabled(true); 
     map.setMyLocationEnabled(true); 
     map.setTrafficEnabled(true); 

     map.setOnMarkerClickListener(new OnMarkerClickListener() { 

      @Override 
      public boolean onMarkerClick(Marker arg0) { 
       // TODO Auto-generated method stub 
       if(arg0.getTitle().equals(a)){ 
       Toast.makeText(getApplicationContext(),"Ahmedabad", 0).show(); 
       } 
       else 
       { 
        Toast.makeText(getApplicationContext(),"Baroda", 0).show(); 
       } 

       return false; 
      } 
     }); 
     map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 

      @Override 
      public void onInfoWindowClick(Marker arg0) { 
       // TODO Auto-generated method stub 
       if(arg0.getTitle().equals(a)){ 
       Intent i =new Intent(getApplicationContext(),SecondActivity.class); 
       i.putExtra("ahm", a); 
       startActivity(i); 
       } 
       else{ 
       Intent i =new Intent(getApplicationContext(),SecondActivity.class); 
       i.putExtra("brd", b); 
       startActivity(i); 
       } 
      //Toast.makeText(getApplicationContext(), "Check",0).show();  
      } 
     }); 

    } 

} 

second.java

package com.example.mapviewdemo; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.webkit.WebView; 

public class SecondActivity extends Activity { 
WebView v; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_second); 
    v=(WebView)findViewById(R.id.webView1); 
    Bundle b =getIntent().getExtras(); 
    b.getString("ahm"); 
    b.getString("brd"); 


    } 



} 

main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 



</RelativeLayout> 

second.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".SecondActivity" > 

    <WebView 
     android:id="@+id/webView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" /> 

</RelativeLayout> 

回答

2

在使用谷歌地图的Android API V2,在信息窗口的任何部分点击被视为信息窗口点击事件,你不能明确是否distingusigh被点击片段或任何其他部分。您的点击侦听器代码似乎是正确的。当你发现点击了哪个标记的信息窗口,你可以做任何的以下方法2:

1,直接通过传递所需的URL作为参数调用网页视图:

Uri uri = Uri.parse("http://www.yourlocationspecificuri.com"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 

2,打电话给你的第二个活动正如你现在所做的那样,然后在阅读意图了解被点击的标记之后,启动具有所需url的webview:

v.loadUrl("http://www.yourlocationspecificuri.com"); 
+0

Thanx ... bro ... :) – jigar

相关问题