Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在谷歌地图android中使用来自服务器的图像作为标记pin_Java_Android_Eclipse_Google Maps - Fatal编程技术网

Java 在谷歌地图android中使用来自服务器的图像作为标记pin

Java 在谷歌地图android中使用来自服务器的图像作为标记pin,java,android,eclipse,google-maps,Java,Android,Eclipse,Google Maps,我想使用服务器上的图像作为谷歌地图项目的pin图标。但是我得到了一个空指针异常。代码如下 package com.igloo.storelocater; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org

我想使用服务器上的图像作为谷歌地图项目的pin图标。但是我得到了一个空指针异常。代码如下

package com.igloo.storelocater;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.igloo.classes.ConnectionDetector;
import com.igloo.classes.Store_data;




import com.igloo.constants.Constants.Config;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {
String URL_store="http://footballultimate.com/storelocator/index.php/api/getStoreData";
String URL_image="http://footballultimate.com/storelocator/resource/uploads/";
private ConnectionDetector cd;
private GoogleMap googleMap;
FragmentManager fragManager;
ProgressDialog progressDialog;
double current_latitude,current_longitude;
int bound_radius=10;
HttpResponse response;
String result;
JSONObject jsonobj;
JSONArray category_array;
String[] catarr;
Store_data sobj;
ArrayList<Store_data> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cd = new ConnectionDetector(MainActivity.this);
        Config.isInternetPresent = cd.isConnectingToInternet();
        if (!Config.isInternetPresent) {

            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            // Shuld be fail icon
            builder.setIcon(R.drawable.ic_launcher);
            builder.setMessage("Connection Not Available !" + "\n"
                    + "Please enable your Internet Connection");
            builder.setTitle("INTERNET CONNECTION");
            builder.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
        else{
            getcurrentlocation();
        initialiseMap();
        new RetrieveStoreDetails().execute();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public void getcurrentlocation()
    {
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        // Creating a criteria object to retrieve provider
        Criteria criteria = new Criteria();
        // Getting the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);
        // Getting Current Location
        Location location = locationManager.getLastKnownLocation(provider);
     // Getting latitude of the current location
        current_latitude=location.getLatitude();

        // Getting longitude of the current location
         current_longitude= location.getLongitude();

    }
    public void initialiseMap()
    {
        if (googleMap == null) {
             googleMap = ( (SupportMapFragment) getSupportFragmentManager().findFragmentById(
                        R.id.map)).getMap();


       }
        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
        else
        {
        googleMap.setMyLocationEnabled(true);
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        googleMap.getUiSettings().setCompassEnabled(true);
//          UiSettings uiSettings = googleMap.getUiSettings();
//          uiSettings.setMyLocationButtonEnabled(true);



            }
            //locationManager.requestLocationUpdates(provider, 20000, 0, this);
        LatLng latLng = new LatLng(current_latitude, current_longitude);
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

        // Zoom in the Google Map
        //googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12.0f));

        }



    public class RetrieveStoreDetails  extends AsyncTask<String,Void,Void>
    {
            @Override
            protected void onPreExecute() {
                progressDialog = new ProgressDialog(MainActivity.this); 
                progressDialog.setTitle("Processing...");
                progressDialog.setMessage("Please wait...");
                progressDialog.setCancelable(false);
                progressDialog.show();
            }
        @Override
        protected Void doInBackground(String... arg0) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(URL_store);
            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            pairs.add(new BasicNameValuePair("current_latitude",""+current_latitude));
            pairs.add(new BasicNameValuePair("current_longitude",""+current_longitude));
            pairs.add(new BasicNameValuePair("bound_radius",""+bound_radius));
            try {
                httppost.setEntity(new UrlEncodedFormEntity(pairs));
                response = httpclient.execute(httppost);
                result=responsetostring.getResponseBody(response);

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

            return null;
        }
        @Override
        protected void onPostExecute(Void result1) {

            getstorevalues(result);
            try{
                   if(progressDialog.isShowing()){
                            progressDialog.dismiss();
                   }  
            }
          catch(Exception e){
              e.printStackTrace();
          }
          finally
          {
               progressDialog.dismiss();
          }

        }

        }
        public void getstorevalues(String result)
        {
            if(result!=null)
            {

                try {
                    list=new ArrayList<Store_data>();
                    jsonobj=new JSONObject(result);
                    category_array=jsonobj.getJSONArray("category");
                    catarr=new String[category_array.length()];
                    JSONObject store_data=jsonobj.getJSONObject("store_data");
                    for(int i=0;i<category_array.length();i++)
                    {
                        catarr[i]=category_array.getString(i);
                    }
                    for(int i=0;i<category_array.length();i++)
                    {
                        JSONArray arrsub=store_data.getJSONArray(catarr[i]);
                        for(int j=0;j<arrsub.length();j++)
                        {
                            sobj=new Store_data();
                            JSONObject d=arrsub.getJSONObject(j);

                            sobj.store_name=d.getString("store_name");
                            sobj.store_image=d.getString("store_image");
                            sobj.store_address=d.getString("store_address");
                            sobj.store_phone=d.getString("store_phone");
                            sobj.store_description=d.getString("store_description");
                            sobj.store_url=d.getString("store_url");
                            sobj.store_latitude=d.getString("store_latitude");
                            sobj.store_longitude=d.getString("store_longitude");
                            sobj.category=catarr[i];
                            list.add(sobj);
                        }
                    }

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

            }
            setvaluesonmap();
        }

    public void setvaluesonmap()
    {
    for(int i=0;i<list.size();i++)
    {
        Store_data s=list.get(i);

        MarkerOptions marker = new MarkerOptions().position(new LatLng(Double.parseDouble(s.store_latitude),Double.parseDouble(s.store_longitude))).title(s.store_name);
      marker.icon(BitmapDescriptorFactory.fromPath(URL_image+s.category+".png"));
      // adding marker
      googleMap.addMarker(marker);
    }
    }

}
问题代码似乎是

MarkerOptions marker = new MarkerOptions().position(new LatLng(Double.parseDouble(s.store_latitude),Double.parseDouble(s.store_longitude))).title(s.store_name);
      marker.icon(BitmapDescriptorFactory.fromPath(URL_image+s.category+".png"));
      // adding marker
      googleMap.addMarker(marker);
URL是正确的,但我仍然收到错误。请帮助

仅适用于本地文件(“从绝对文件路径创建位图描述符”)。您需要自己下载图像

MarkerOptions marker = new MarkerOptions().position(new LatLng(Double.parseDouble(s.store_latitude),Double.parseDouble(s.store_longitude))).title(s.store_name);
      marker.icon(BitmapDescriptorFactory.fromPath(URL_image+s.category+".png"));
      // adding marker
      googleMap.addMarker(marker);