如何通过地图上的标记拨打电话

时间:2014-08-08 14:51:53

标签: android google-maps-markers

我在地图中有一些表示库的标记(取自JSON文件)。 现在我想让用户可以通过标记拨打电话/发送电子邮件/访问网站到这些图书馆,有人可以帮助我吗?

 // Setting OnClickEvent listener for the GoogleMap
    map.setOnMapClickListener(new OnMapClickListener() {
        public void onMapClick(LatLng latlng, String nome, String indirizzo, String tel, String fax, String url, String email) {
            addMarkerBiblio(latlng, nome, indirizzo, tel, fax, url, email);
            }

        @Override
        public void onMapClick(LatLng arg0) {
            // TODO Auto-generated method stub

        }


    });

// Starting locations retrieve task
        new RetrieveTask().execute();  

}



//MARKER DELLE BIBLIO


// Adding marker on the GoogleMaps
    private void addMarkerBiblio(LatLng latlng, String nome, String indirizzo, String tel, String fax, String url, String email) {
        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(latlng);
        markerOptions.snippet(indirizzo);
        markerOptions.title(nome);
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_action_biblio));
        boolean visible = false;
        markerOptions.visible(visible);
        Marker biblioM = map.addMarker(markerOptions);
        biblioMarker.add(biblioM);




    }


    // Background task to retrieve locations from remote mysql server
    private class RetrieveTask extends AsyncTask<Void, Void, String>{

        @Override
        protected String doInBackground(Void... params) {
            String strUrl = "http://hyperion.sal.disco.unimib.it:8080/RESTfulProject/REST/biblio";              
            URL url = null;
            StringBuffer sb = new StringBuffer();
            try {
                url = new URL(strUrl);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.connect();
                InputStream iStream = connection.getInputStream();              
                BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));         
                String line = "";               
                while( (line = reader.readLine()) != null){
                    sb.append(line);
                }

                reader.close();
                iStream.close();                            

            } catch (MalformedURLException e) {
                e.printStackTrace();

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

            }       
            return sb.toString();
        }

        @Override
        protected void onPostExecute(String result) {           
            super.onPostExecute(result);
            new ParserTask().execute(result);
        }

    }

    // Background thread to parse the JSON data retrieved from MySQL server
    private class ParserTask extends AsyncTask<String, Void, List<HashMap<String, String>>>{
        @Override
        protected List<HashMap<String,String>> doInBackground(String... params) {
            MarkerJSONParser markerParser = new MarkerJSONParser();
            JSONObject json = null;
            try {
                json = new JSONObject(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            List<HashMap<String, String>> markersList = markerParser.parse(json);
            return markersList;
        }

        @Override
        protected void onPostExecute(List<HashMap<String, String>> result) {
            for(int i=0; i<result.size();i++){
                HashMap<String, String> marker = result.get(i);
                LatLng latlng = new LatLng(Double.parseDouble(marker.get("lat")), Double.parseDouble(marker.get("lng")));
                String nome = marker.get("nome");
                String indirizzo = marker.get("indirizzo");
                String tel = marker.get("tel");
                String fax = marker.get("fax");
                String url = marker.get("url");
                String email = marker.get("email");
                addMarkerBiblio(latlng,nome,indirizzo,tel,fax,url,email);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您可以使用

OnInfoWindowClickListener

能够捕捉您创建的每个标记的信息窗口中的“点击”。

然后你可以使用“onInfoWindowClick”通过Intent打开另一个活动,例如Webview

@Override
public void onInfoWindowClick(Marker marker) {

    Intent intent = new Intent(MainActivity.this,Web.class);
    Log.d(TAG, "URL: " + marker.getSnippet());
    intent.putExtra("url", marker.getSnippet());
     startActivity(intent);
}

对于电话,您可以使用呼叫意图

Intent intent = new Intent(Intent.ACTION_DIAL);

如果您有多个选项可供选择,我会在此处使用对话框,然后使用对话框结果打开Intent