0

我的概念是,當搜索地點在谷歌地圖中這個地方的圖像是添加在標記,標記是圖像視圖,我用這個鏈接的serch位置代碼http://wptrafficanalyzer.in/blog/android-geocoding-showing-user-input-location-on-google-map-android-api-v2/ 並在此代碼中使用圖像視圖的owen標記。所以我怎麼可以添加圖片如何在Android中的谷歌地圖標記中添加搜索地點圖像

公共類GeocoderTask擴展的AsyncTask> {

@Override 
    protected List<Address> doInBackground(String... locationName) { 
     // Creating an instance of Geocoder class 
     Geocoder geocoder = new Geocoder(getBaseContext()); 
     List<Address> addresses = null; 

     respo=myServiceToHttp.makeServiceCall("https://maps.googleapis.com/maps/api/place/textsearch/json?query="+addresses+"&key=Your Server KEy", MyServiceToHttp.GET); 
     System.out.println("MyGeocoderTask.doInBackground()------Image---->"+respo); 

     try { 

      String placeid=null; 

      JSONObject jsonObject=new JSONObject(respo); 

      JSONArray array=jsonObject.getJSONArray("results"); 
      //System.out.println("GeocoderTask.doInBackground()---------->"+array); 

      for (int j = 0; j < array.length(); j++) { 

       JSONObject jsonObject2= array.getJSONObject(j); 

       placeid=jsonObject2.getString("place_id"); 

       System.out.println("GeocoderTask.doInBackground()------PlaceID-->"+placeid); 

       respo2=myServiceToHttp.makeServiceCall("https://maps.googleapis.com/maps/api/place/details/json?placeid="+placeid+"&key=Your Server KEy", MyServiceToHttp.GET); 

       System.out.println("Response2-->>>>" +respo2); 
      } 


     } catch (JSONException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 



     try { 


      // Getting a maximum of 3 Address that matches the input text 
      addresses = geocoder.getFromLocationName(locationName[0],4); 


     }catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return addresses; 
    } 


    @Override 
    protected void onPostExecute(List<Address> addresses) { 

     if(addresses==null || addresses.size()==0){ 
      Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show(); 
     } 

     // Clears all the existing markers on the map 
     googleMap.clear(); 

     // Adding Markers on Google Map for each matching address 
     for(int i=0;i<addresses.size();i++){ 


      Address address = (Address) addresses.get(i); 

      // Creating an instance of GeoPoint, to display in Google Map 
      latLng = new LatLng(address.getLatitude(), address.getLongitude()); 


      String addressText = String.format("%s, %s, %s,%s", 
         address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(1) : "", 
         address.getThoroughfare(), 
         // Locality is usually a city 
         address.getLocality(), 
         // The country of the address 
         address.getCountryName()); 

      marker = new MarkerOptions(); 
      marker.position(latLng); 
      marker.title(addressText); 


      //googleMap.addMarker(marker); 

      // Locate the first location 
      if(i==0) 
       googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 
     } 



    } 
} 
+1

https://developers.google.com/places/documentation/details – 2014-09-30 10:07:14

+0

檢查此以及http://wptrafficanalyzer.in/blog/custom-marker-icon-for-google-maps-android-api-v2/ – Goofy 2014-09-30 10:16:48

+0

這是我的方式respo是exicute和顯示地址響應,但其顯示總是canda區迴應 – 2014-09-30 12:05:12

回答

0

就試試這個:

// Uses a custom icon. 
    mIndia = mMap.addMarker(new MarkerOptions() 
     .position(SYDNEY) 
     .title("Sydney") 
     .snippet("Population: 4,627,300") 
     .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow))); 

As this just replaces the marker with an image you might want to use a Canvas to draw more complex and fancier stuff: 

Bitmap.Config conf = Bitmap.Config.ARGB_8888; 
Bitmap bmp = Bitmap.createBitmap(80, 80, conf); 
Canvas canvas1 = new Canvas(bmp); 

// paint defines the text color, 
// stroke width, size 
Paint color = new Paint(); 
color.setTextSize(35); 
color.setColor(Color.BLACK); 

//modify canvas 
canvas1.drawBitmap(BitmapFactory.decodeResource(getResources(), 
    R.drawable.user_picture_image), 0,0, color); 
canvas1.drawText("User Name!", 30, 40, color); 

//add marker to Map 
mMap.addMarker(new MarkerOptions().position(USER_POSITION) 
    .icon(BitmapDescriptorFactory.fromBitmap(bmp)) 
    // Specifies the anchor to be at a particular point in the marker image. 
    .anchor(0.5f, 1)); 
+0

tnx .......但我使用serch地方代碼linkhttp://wptrafficanalyzer.in/blog/android-geocoding-showing-user-input-location-on-google-map-android-api-v2/.... – 2014-09-30 10:38:39