2013-04-09 83 views
0

我在嘗試將多個Geopoint位置繪製到Google地圖上時出現此錯誤。我正在通過PHP和JSON從MySQL數據庫讀取經緯度。我看過主要的例子,如Couldn't get connection factory client,Couldn't get connection factory client - fighting with Google Maps,Android MapActivity : Couldn't get connection factory client
我可以確認它不是無效的API密鑰,因爲我生成了2個不同的密鑰並返回了相同的錯誤。這也不是API級別的問題,我嘗試在API級別17和級別8上運行應用程序,但仍然沒有喜悅。當我運行的代碼,它顯示的地圖沒有問題,然後獲取到的「錯誤顯示內容的」我的異常敬酒消息
這裏是我的mapview.java代碼:
由於;無法讓Geopoints添加到谷歌地圖;無法獲取連接工廠客戶端

import java.util.ArrayList; 
import java.util.List; 

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.NameValuePair; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import android.graphics.drawable.Drawable; 
import android.net.ParseException; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.Toast; 

import java.io.BufferedReader; 
import java.io.InputStream; 
import java.io.InputStreamReader; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay; 
import com.google.android.maps.OverlayItem; 

public class mapview extends MapActivity 
{ 

//protected MapView mapview; 

JSONArray jarray; 
String result=null; 
InputStream is=null; 
StringBuilder sb=null; 

double LAT; 
double LNG; 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mapview); 

    MapView mapview = (MapView) findViewById(R.id.mapview); 
    mapview.setBuiltInZoomControls(true); 

    //ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

    try 
    { 

     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("http://10.0.2.2/displaymarkers.php"); 
     //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
     HttpResponse response = httpclient.execute(httppost); 
     HttpEntity entity = response.getEntity(); 
     is = entity.getContent(); 

    } 

    catch(Exception e) 
    { 
     Log.e("log_tag", "Error in http connection"+e.toString()); 
    } 


     try{   


     jarray = new JSONArray("$json_output[]"); 
     JSONObject json_data = null; 
       for(int i = 0; i < jarray.length(); i++) 
       { 
        json_data = jarray.getJSONObject(i); 

        LAT=json_data.getDouble("lat"); 
        LNG=json_data.getDouble("lng"); 

        GeoPoint point = new GeoPoint((int)(LAT * 1E6), (int)(LNG * 1E6)); 
        OverlayItem overlayitem = new OverlayItem(point, "TEXT", null); 

        List<Overlay> mapOverlays = mapview.getOverlays(); 
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker); 
        myItemizedOverlay itemizedoverlay = new myItemizedOverlay(drawable, this); 

        MapController mapController = mapview.getController(); 

        //mapController.animateTo(point); 
        mapController.setZoom(8); 

        itemizedoverlay.addOverlay(overlayitem); 
        mapOverlays.add(itemizedoverlay); 
       } 
      } 
      catch(JSONException e1) 
      { 
      Toast.makeText(getBaseContext(), "Error displaying contents" ,Toast.LENGTH_LONG).show(); 
      }  
       catch (ParseException e1) 
       { 
       e1.printStackTrace(); 
       } 
    } 
    @Override 
    protected boolean isRouteDisplayed() 
    { 
     return false; 
    } 
} 

這是我ItemizedOverlay.java代碼:

import java.util.ArrayList; 

    import android.app.AlertDialog; 
    import android.content.Context; 
    import android.graphics.drawable.Drawable; 

    import com.google.android.maps.OverlayItem; 
    import com.google.android.maps.ItemizedOverlay; 


    public class myItemizedOverlay extends ItemizedOverlay 
    { 

     private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 
     private Context mContext; 

     public myItemizedOverlay(Drawable marker, Context context) 
     { 
      super(boundCenterBottom(marker)); 
      mContext = context; 

     } 

     public void addOverlay(OverlayItem overlay) 
     { 
      mapOverlays.add(overlay); 
      this.populate(); 
     } 


     @Override 
     protected OverlayItem createItem(int i) 
     { 
      return mapOverlays.get(i); 
     } 

     @Override 
     public int size() 
     { 
      return mapOverlays.size(); 
     } 

     @Override 
     protected boolean onTap(int index) 
     { 
      OverlayItem item = mapOverlays.get(index); 
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
      dialog.setTitle(item.getTitle()); 
      dialog.setMessage(item.getSnippet()); 
      dialog.show(); 
      return true; 
     } 

    } 

我希望得到任何幫助,我要提前致謝。

回答

0

如果您最近生成了這些密鑰,您將無法獲得結果,因爲API v1已被棄用且無法使用。

您可能要切換到地圖API V2:https://developers.google.com/maps/documentation/android/

不要試圖用你的舊代碼,因爲新的API不共享API v1的任何代碼。

+0

可能是我唯一的選擇,謝謝你的輸入。我懷疑我會得到比你更好的答案,所以我會接受它,並再次嘗試新版本。再次感謝。 – jibbajava 2013-04-10 01:12:29

相關問題