Java 汉字拆分转为拼音 及根据经纬度获取所在位置

java网络代码拼凑人

package com.ruoyi.hfiveinterface.util;import com.alibaba.fastjson.JSONObject;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.junit.Test;
import org.springframework.stereotype.Service;import java.net.URL;@Service
public class ChineseToPinyinUtil {/*** 汉字转为拼音* @param chinese* @return*/public  String toPinyin(String chinese){String pinyinStr = "";char[] newChar = chinese.toCharArray();HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);for (int i = 0; i < newChar.length; i++) {if (newChar[i] > 128) {try {pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0];} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}else{pinyinStr += newChar[i];}}return pinyinStr;}/*** 获取字符串拼音的第一个字母* @param chinese* @return*/public  String getFirstCharUpperCase(String chinese){String pinyinStr = "";char[] newChar = chinese.toCharArray();  //转为单个字符HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);for (int i = 0; i < newChar.length; i++) {if (newChar[i] > 128) {try {pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0].charAt(0);} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}else{pinyinStr += newChar[i];}}return pinyinStr.substring(0, 1).toUpperCase();}/*** 得到汉字首字母的拼音* @param str* @return 拼音首字母(大写)*/public static String getPinYinHeaderChar(String str){String convert="";for ( int i = 0; i < str.length(); i++ ) {char word=str.charAt(i);String[] pinYinArray=PinyinHelper.toHanyuPinyinStringArray(word);if ( pinYinArray!=null ){convert+=pinYinArray[0].charAt(0);}else {convert+=word;}}return convert.toUpperCase();}/*** 根据经纬度 获取 用户的具体位置* @param lat* @param log* @return*/public String getAdd(String lat, String log) {// log lat// 参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)//String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + log + "&type=010";String urlString = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=ZyCkKVoOyVa8vemSLStGV39XicQj4uAd&output=json&coordtype=wgs84ll&location=" + lat + "," + log.trim();String res = "";String formatted_address = "";try {URL url = new URL(urlString);java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();conn.setDoOutput(true);conn.setRequestMethod("POST");java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));String line;while ((line = in.readLine()) != null) {res += line + "\n";}in.close();
//            {"status":0,"result":{"location":{"lng":121.50989050677055,"lat":31.229327880651959},"formatted_address":"上海市黄浦区中山南路187","business":"外滩,陆家嘴,董家渡","addressComponent":{"country":"中国","country_code":0,"country_code_iso":"CHN","country_code_iso2":"CN","province":"上海市","city":"上海市","city_level":2,"district":"黄浦区","town":"","town_code":"","adcode":"310101","street":"中山南路","street_number":"187","direction":"东北","distance":"91"},"pois":[],"roads":[],"poiRegions":[],"sematic_description":"","cityCode":289}}JSONObject jsStr = JSONObject.parseObject(res); //将字符串{“id”:1}//            JSONArray jsonArray = jsStr.getJSONArray("HeWeather6");String result = jsStr.getString("result");
//            System.out.println(result);JSONObject resultjsStr = JSONObject.parseObject(result);formatted_address = resultjsStr.getString("formatted_address");
//            System.out.println(formatted_address);//int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值} catch (Exception e) {System.out.println("error in wapaction,and e is " + e.getMessage());}return formatted_address;}/*** 根据经纬度 获取 城市 的数据* @param lat* @param log* @return*/public static String getLocation(String lat, String log) {// log lat// 参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)//String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + log + "&type=010";String urlString = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=ZyCkKVoOyVa8vemSLStGV39XicQj4uAd&output=json&coordtype=wgs84ll&location=" + lat + "," + log.trim();String res = "";String formatted_address = "";try {URL url = new URL(urlString);java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();conn.setDoOutput(true);conn.setRequestMethod("POST");java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));String line;while ((line = in.readLine()) != null) {res += line + "\n";}in.close();
//            {"status":0,"result":{"location":{"lng":121.50989050677055,"lat":31.229327880651959},"formatted_address":"上海市黄浦区中山南路187","business":"外滩,陆家嘴,董家渡","addressComponent":{"country":"中国","country_code":0,"country_code_iso":"CHN","country_code_iso2":"CN","province":"上海市","city":"上海市","city_level":2,"district":"黄浦区","town":"","town_code":"","adcode":"310101","street":"中山南路","street_number":"187","direction":"东北","distance":"91"},"pois":[],"roads":[],"poiRegions":[],"sematic_description":"","cityCode":289}}JSONObject jsStr = JSONObject.parseObject(res); //将字符串{“id”:1}//            JSONArray jsonArray = jsStr.getJSONArray("HeWeather6");String result = jsStr.getString("result");
//            System.out.println(result);JSONObject resultjsStr = JSONObject.parseObject(result);////System.out.println("打印字符串"+resultjsStr);String locationInfo=resultjsStr.getString("addressComponent");//System.out.println("打印返回结果详细信息"+locationInfo);JSONObject jsonObjLocation = JSONObject.parseObject(locationInfo);//System.out.println(jsonObjLocation);formatted_address = jsonObjLocation.getString("city");
//            System.out.println(formatted_address);//int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值} catch (Exception e) {System.out.println("error in wapaction,and e is " + e.getMessage());}return formatted_address;}/*** 根据经纬度 获取 省份 和 城市 的数据* @param lat* @param log* @return*/public String getProvinceAndCity(String lat, String log) {// log lat// 参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)//String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + log + "&type=010";String urlString = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=ZyCkKVoOyVa8vemSLStGV39XicQj4uAd&output=json&coordtype=wgs84ll&location=" + lat + "," + log.trim();String res = "";String formatted_address = "";try {URL url = new URL(urlString);java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();conn.setDoOutput(true);conn.setRequestMethod("POST");java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));String line;while ((line = in.readLine()) != null) {res += line + "\n";}in.close();
//            {"status":0,"result":{"location":{"lng":121.50989050677055,"lat":31.229327880651959},"formatted_address":"上海市黄浦区中山南路187","business":"外滩,陆家嘴,董家渡","addressComponent":{"country":"中国","country_code":0,"country_code_iso":"CHN","country_code_iso2":"CN","province":"上海市","city":"上海市","city_level":2,"district":"黄浦区","town":"","town_code":"","adcode":"310101","street":"中山南路","street_number":"187","direction":"东北","distance":"91"},"pois":[],"roads":[],"poiRegions":[],"sematic_description":"","cityCode":289}}JSONObject jsStr = JSONObject.parseObject(res); //将字符串{“id”:1}//            JSONArray jsonArray = jsStr.getJSONArray("HeWeather6");String result = jsStr.getString("result");
//            System.out.println(result);JSONObject resultjsStr = JSONObject.parseObject(result);////System.out.println("打印字符串"+resultjsStr);String locationInfo=resultjsStr.getString("addressComponent");//System.out.println("打印返回结果详细信息"+locationInfo);JSONObject jsonObjLocation = JSONObject.parseObject(locationInfo);//System.out.println("打印省市区返回的json字符串" + jsonObjLocation);String province = jsonObjLocation.getString("province");String city = jsonObjLocation.getString("city");formatted_address =province+ ","+city;
//            System.out.println(formatted_address);//int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值} catch (Exception e) {System.out.println("error in wapaction,and e is " + e.getMessage());}return formatted_address;}/*** 根据经纬度 获取 省份 和 城市 和具体城市信息 的数据* @param lat* @param log* @return*/public String getProvinceAndCityAndInfoAddress(String lat, String log) {// log lat// 参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)//String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + log + "&type=010";String urlString = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=ZyCkKVoOyVa8vemSLStGV39XicQj4uAd&output=json&coordtype=wgs84ll&location=" + lat + "," + log.trim();String res = "";String formatted_address = "";try {URL url = new URL(urlString);java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();conn.setDoOutput(true);conn.setRequestMethod("POST");java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));String line;while ((line = in.readLine()) != null) {res += line + "\n";}in.close();
//            {"status":0,"result":{"location":{"lng":121.50989050677055,"lat":31.229327880651959},"formatted_address":"上海市黄浦区中山南路187","business":"外滩,陆家嘴,董家渡","addressComponent":{"country":"中国","country_code":0,"country_code_iso":"CHN","country_code_iso2":"CN","province":"上海市","city":"上海市","city_level":2,"district":"黄浦区","town":"","town_code":"","adcode":"310101","street":"中山南路","street_number":"187","direction":"东北","distance":"91"},"pois":[],"roads":[],"poiRegions":[],"sematic_description":"","cityCode":289}}JSONObject jsStr = JSONObject.parseObject(res); //将字符串{“id”:1}//            JSONArray jsonArray = jsStr.getJSONArray("HeWeather6");String result = jsStr.getString("result");
//            System.out.println(result);JSONObject resultjsStr = JSONObject.parseObject(result);////System.out.println("打印字符串"+resultjsStr);String locationInfo=resultjsStr.getString("addressComponent");//System.out.println("打印返回结果详细信息"+locationInfo);JSONObject jsonObjLocation = JSONObject.parseObject(locationInfo);//System.out.println("打印省市区返回的json字符串" + jsonObjLocation);String province = jsonObjLocation.getString("province");String city = jsonObjLocation.getString("city");String district = jsonObjLocation.getString("district");String street = jsonObjLocation.getString("street");System.out.println(district + street);//"district":"黄浦区","town":"","town_code":"","adcode":"310101","street":"中山南路"formatted_address =province+ ","+city+","+district+street;
//            System.out.println(formatted_address);//int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值} catch (Exception e) {System.out.println("error in wapaction,and e is " + e.getMessage());}return formatted_address;}}

Java 汉字拆分转为拼音 及根据经纬度获取所在位置相关推荐

  1. java将中文转为拼音

    java将中文转为拼音 项目需求,需要将一批工号批量入库,但产品经理提供的却是中文--没办法,只好用程序转了. 做法是将人名保存为文本文件,每行一个.并且采用pinyin4j包进行转换,值得提的是pi ...

  2. java腾讯地图根据经纬度获取具体位置

    腾讯地图 java腾讯地图根据经纬度获取具体位置 java腾讯地图根据经纬度获取具体位置 package com.fengdi.lianmeng.util.tencent;import com.fen ...

  3. 根据经纬度获取地址 :位置名称 区 市 省 国家 邮编

    方式1: 根据经纬度获取: 省 市 区 位置名称 import java.net.URL; import java.util.HashMap; import java.util.Map; import ...

  4. 数字排在最前,英文字母其次,汉字则按照拼音进行排序,获取中文首字母

    中文名称,按照A-Z方式进行排序. import cn.hutool.extra.pinyin.PinyinUtil; import com.alibaba.nacos.client.utils.St ...

  5. java point类求两点间距离_JAVA 根据经纬度获取两点之间的距离(转载)

    原文https://blog.csdn.net/jk940438163/article/details/83147557 思路: 1. 地球本身是个不规则的球体,这里将其看着一个规制球体 2. 半径取 ...

  6. java如何接受字符_java中string怎么获取指定位置的字符

    //截取#之前的字符串String str = "sdfs#d";str.substring(0, str.indexOf("#"));// 输出的结果为:sd ...

  7. java 使用onvif协议 PTZ 登录认证,获取摄像头位置, 控制摄像头转动,digest认证,拍照截图

    1. 介绍 前面公司做摄像头相关的项目,一开始使用的海康威视提供的相关接口来控制摄像头转动,获取位置等,后面发现由于大华的很多摄像头使用该接口却行不通,后面所以就转用通用的 onvif 协议来做相关的 ...

  8. 百度地图根据经纬度获取实际位置纠偏

    前言:在使用百度地图的时候,根据经纬度地址逆解析的时候,获取的位置不是很精确,只能获取到省.市县.路名.街道.号,有时只能获取省市县,位置不是很精确.所以使用百度地图位置纠偏方法获取比较精确的实际位置 ...

  9. java汉字转换成拼音_Java代码将汉字转换成拼音

    package com.sucre; //导入的jar包 import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pi ...

最新文章

  1. 第十八章 8string类insert成员函数的使用
  2. 简单几步教你去除开机出现扫描硬盘!
  3. 应用程序缓存_应用程序模块和实体缓存
  4. webservice 心得
  5. 2440 linux文件写,添加yaffs2文件系统 - Linux2.6.39在S3C2440上的移植_Linux编程_Linux公社-Linux系统门户网站...
  6. 【报告分享】中国数据智能应用趋势报告:解码数据中台最佳实践,企业数字化转型新引擎.pdf(附下载链接)...
  7. mysql中字符串处理替换字符replace和连接字符串函数concat
  8. 强化学习中值迭代收敛性推理证明
  9. Go语言:生成随机数
  10. 单链表的实现 (C语言版 数据结构 严蔚敏)
  11. C++解决猜大小问题
  12. CSP-S 2020 T1 P7075 儒略日
  13. 力盟科技冲刺上市:主要通过力盟传媒展业,木瓜移动等亦在努力
  14. 微信小程序 保存图片 wx.saveImageToPhotosAlbum
  15. sd卡突然所有文件都无法删除,在手机中会提示‘无法删除’,并且无法格式化,并且无法写入文件,
  16. Python大神80行代码实现“头脑王者”,运营窍诀躺着教你赚钱!
  17. Note: Bimodal Content Defined Chunking for Backup Streams
  18. Designing Websites for Performance 如何设计高性能网站 Lynda课程中文字幕
  19. 华为Atlas张迪煊:在最好的时代,做最强AI算力底座
  20. 浙江大学计算机学院博士论文格式,浙江大学博士学位论文模板.doc

热门文章

  1. 移动硬盘拷贝东西时快时慢的问题
  2. android 获取系统的ram和rom,以及可用的
  3. CMOS/CCD图像传感器的工作原理
  4. python判断字符串是否含有非中文字符的日文/韩文字符
  5. 紧接着这一刻的是钟声漫过夏季的树木
  6. 短视频营销的模式和流程
  7. 现在做哪个行业好赚钱
  8. 【温故知新系列】软件测试原则的7个基本原则
  9. 3.23学习内容,竖立seekbar,sql获取删除重复数据
  10. 华为手机便签删了怎么找回