Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
如何在android中的google地图标记中添加搜索位置图像_Android_Google Maps_Google Places Api_Google Geocoding Api - Fatal编程技术网

如何在android中的google地图标记中添加搜索位置图像

如何在android中的google地图标记中添加搜索位置图像,android,google-maps,google-places-api,google-geocoding-api,Android,Google Maps,Google Places Api,Google Geocoding Api,我的想法是,当在谷歌地图中搜索地点时,这个地点的图像是附加标记,标记是图像视图,我使用这个链接中的serch位置代码 在这段代码中使用owen标记,即图像视图。那么我如何添加图像呢 公共类GeocoderTask扩展异步任务>{ @Override protected List<Address> doInBackground(String... locationName) { // Creating an instance of Geocoder cl

我的想法是,当在谷歌地图中搜索地点时,这个地点的图像是附加标记,标记是图像视图,我使用这个链接中的serch位置代码 在这段代码中使用owen标记,即图像视图。那么我如何添加图像呢

公共类GeocoderTask扩展异步任务>{

    @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));
        }



    }
}
@覆盖
受保护列表doInBackground(字符串…位置名称){
//创建Geocoder类的实例
Geocoder Geocoder=新的Geocoder(getBaseContext());
列表地址=空;
respo=myServiceToHttp.makeServiceCall(“https://maps.googleapis.com/maps/api/place/textsearch/json?query=“+addresses+”&key=您的服务器密钥”,MyServiceToHttp.GET);
System.out.println(“MyGeocoderTask.doInBackground()----Image-->”+respo);
试一试{
字符串placeid=null;
JSONObject JSONObject=新的JSONObject(respo);
JSONArray数组=jsonObject.getJSONArray(“结果”);
//System.out.println(“GeocoderTask.doInBackground()------------>”+数组);
对于(int j=0;j”+PlaceID);
respo2=myServiceToHttp.makeServiceCall(“https://maps.googleapis.com/maps/api/place/details/json?placeid=“+placeid+”&key=您的服务器密钥”,myserviceohttp.GET);
System.out.println(“Response2-->>>”+Response2);
}
}捕获(JSONException e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
试一试{
//获取最多3个与输入文本匹配的地址
addresses=geocoder.getFromLocationName(locationName[0],4);
}捕获(IOE异常){
e、 printStackTrace();
}
返回地址;
}
@凌驾
受保护的void onPostExecute(列表地址){
if(addresses==null | | addresses.size()==0){
Toast.makeText(getBaseContext(),“找不到位置”,Toast.LENGTH_SHORT.show();
}
//清除地图上的所有现有标记
googleMap.clear();
//在谷歌地图上为每个匹配地址添加标记
对于(int i=0;i 0?地址。getAddressLine(1):“”,
address.GetThroughway(),
//地点通常是一个城市
address.getLocation(),
//地址所在国
address.getCountryName());
标记=新标记选项();
标记位置(板条);
标记。标题(地址文本);
//谷歌地图。添加标记(标记);
//找到第一个位置
如果(i==0)
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
}
试试这个:

 // 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));

也请检查此项,这是我的方式respo退出并显示地址响应,但其显示始终为canda area responsetnx……。但我使用此项中的serch位置代码linkhttp://wptrafficanalyzer.in/blog/android-geocoding-showing-user-input-location-on-google-map-android-api-v2/....