我在使用openstreetmap 开发APP的时候,实现输入地名确定位置的功能时出现错误

MainActivity.java文件:

    public class MainActivity extends Activity implements OnClickListener {


      private Button plan;
    private EditText name;  
    private Button find; 
    private Geocoder geocoder;  

    private static final double lat = 39.98773;  
    private static final double lng = 116.37742;

    public MapView mapView=null;

    private ItemizedOverlayWithBubble<ExtendedOverlayItem> poiMarkers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        geocoder = new Geocoder(this);  

        name = (EditText) findViewById(R.id.name);  
        find = (Button) findViewById(R.id.find);

        plan=(Button) findViewById(R.id.plan);
        plan.setOnClickListener(this);
        find.setOnClickListener(this);
        Intent i= getIntent();
        Bundle bundle = i.getExtras();

    //      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    //      StrictMode.setThreadPolicy(policy);

        mapView = (MapView) findViewById(R.id.MapView);
        initMapOverlays(mapView);
        routePlan();
        poiSearch();




    }

其中我目前出现问题的部分是点击按钮获取输入文本实现位置确定代码如下:

    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId()==R.id.plan) {
            Intent intent=new Intent(MainActivity.this,PlanActivity.class);
            startActivity(intent);
        }
        if (v.getId()==R.id.find) {
            String keyword = name.getText().toString();  

            new UpdateSearch().execute(keyword);    


            } 

    }
        /*
     * 异步_地点查询
     */
    class UpdateSearch extends AsyncTask<String, Void, List<Address>>{



        @Override
        protected List<Address> doInBackground(String... params) {
            // TODO Auto-generated method stub

            GeocoderNominatim coderNominatim = new GeocoderNominatim(MainActivity.this);
            List<Address> geoResults = null;
            try {
                geoResults = coderNominatim.getFromLocationName(params[0], 3);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return geoResults;
        }

        @Override
        protected void onPostExecute(List<Address> result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            if (result.size() == 0) { 
                 Toast.makeText(MainActivity.this, "Not found.", Toast.LENGTH_SHORT).show();
         } else {
                Address address = result.get(0);
                Bundle extras = address.getExtras();
                BoundingBoxE6 bb = extras.getParcelable("boundingbox");
                mapView.zoomToBoundingBox(bb);
         } 
        }

    }

在我输入地名“故宫”点击按钮之后程序闪退,部分日至如下:

 07-21 15:23:02.415: W/System(3021): ClassLoader referenced unknown path: /system/framework/com.qualcomm.qti.GBAHttpAuthentication.jar
07-21 15:23:23.520: E/AndroidRuntime(3021): FATAL EXCEPTION: AsyncTask #5
07-21 15:23:23.520: E/AndroidRuntime(3021): Process: com.example.osmdroiddemo, PID: 3021
07-21 15:23:23.520: E/AndroidRuntime(3021): java.lang.RuntimeException: An error occurred while executing doInBackground()
07-21 15:23:23.520: E/AndroidRuntime(3021):     at android.os.AsyncTask$3.done(AsyncTask.java:309)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.lang.Thread.run(Thread.java:818)
07-21 15:23:23.520: E/AndroidRuntime(3021): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/JsonParser;
07-21 15:23:23.520: E/AndroidRuntime(3021):     at org.osmdroid.bonuspack.location.GeocoderNominatim.getFromLocationName(GeocoderNominatim.java:230)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at org.osmdroid.bonuspack.location.GeocoderNominatim.getFromLocationName(GeocoderNominatim.java:271)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at com.example.osmdroiddemo.MainActivity$UpdateSearch.doInBackground(MainActivity.java:360)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at com.example.osmdroiddemo.MainActivity$UpdateSearch.doInBackground(MainActivity.java:1)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at android.os.AsyncTask$2.call(AsyncTask.java:295)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-21 15:23:23.520: E/AndroidRuntime(3021):     ... 4 more
07-21 15:23:23.520: E/AndroidRuntime(3021): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.gson.JsonParser" on path: DexPathList[[zip file "/data/app/com.example.osmdroiddemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.osmdroiddemo-1/lib/arm, /vendor/lib, /system/lib]]
07-21 15:23:23.520: E/AndroidRuntime(3021):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-21 15:23:23.520: E/AndroidRuntime(3021):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
07-21 15:23:23.520: E/AndroidRuntime(3021):     ... 10 more
07-21 15:23:23.520: E/AndroidRuntime(3021):     Suppressed: java.lang.ClassNotFoundException: com.google.gson.JsonParser
07-21 15:23:23.520: E/AndroidRuntime(3021):         at java.lang.Class.classForName(Native Method)
07-21 15:23:23.520: E/AndroidRuntime(3021):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
07-21 15:23:23.520: E/AndroidRuntime(3021):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
07-21 15:23:23.520: E/AndroidRuntime(3021):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
07-21 15:23:23.520: E/AndroidRuntime(3021):         ... 11 more
07-21 15:23:23.520: E/AndroidRuntime(3021):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

日志里提到的什么Json什么的实在是不知道咋去解决,国内关于osm开发的实战很少,所以有没有大神帮忙解决一下,有什么还需要我提供的请留言,谢谢!

1个回答

问题我已经自己解决了,是因为我没有导入一个包叫做gson。然后我通过搜索找到一个合适的包,链接如下:
http://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.0/
如何导包大家可以自行百度。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
如何获取osm xml格式的openstreetmap数据

openstreetmap官网上介绍的OSM XML file的格式是这样的 ![图片说明](https://img-ask.csdn.net/upload/202001/29/1580278469_110234.png) 但是我在openstreetmap上导出的osm文件打开后确是这个样子的 ![图片说明](https://img-ask.csdn.net/upload/202001/29/1580278563_931205.png) 想请问一下大家如何获取官网上介绍的那一种osm格式啊?因为我要将openstreetmap导入ros中,但是roswiki上的功能包貌似只支持第一种格式,第二种导入的时候在rviz中显示不出数据来

openlayers 怎么实现查询功能

我现在需要做一个openstreetmap的开发 需要在地图上做一个搜索功能 有大神帮忙写个例子供我参考一下吗

从openstreetmap获取城市边界

<div class="post-text" itemprop="text"> <p>I'm developing a website and I need to get all the boundaries of an area given depending on the user input. For example, the user want to know the boundaries of a city named x. How should I get it from openstreetmap? I've heard of xapi and osmosis but couldnt find any examples anywhere. Thanks!</p> </div>

在OpenStreetMap中保持页面刷新的缩放级别状态

<div class="post-text" itemprop="text"> <p>In reference to the Open Street Map for Heatmap tutorial in this link </p> <pre><code>http://www.d3noob.org/2014/02/generate-heatmap-with-leafletheat-and.html </code></pre> <p>I want to know how could I keep the state of zoom level when I refresh the page. Suppose I changed the blur value via $_POST and the page refreshes then I go back to the default zoom(10). But I want to be at the same zoom level I was when I just wanted to change the blur value.</p> </div>

如何在openstreetmap中从地图外部打开标记?

<div class="post-text" itemprop="text"> <p>i am using openstreetmap in my project, earlier i used google map in this project but the request limit is lower than what my client needs and he can't afford what google takes to increase the request limit so i had to switch to openstreetmap, i am searching a lot in openstreetmap documentation but not getting the clue that how to open a marker from a link which is outside the map, can you please help me in solving this. This will be a huge help for me.</p> <p>Thanks in advance</p> <p>Hey, I solved it myself, this is the code to open popup of marker from outside the map.</p> <pre> function openMarker(id,lon,lat,html) { jQuery(".olPopup").remove(); marklonLat = new OpenLayers.LonLat(lon,lat) .transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 map.getProjectionObject() // to Spherical Mercator Projection ); var size = new OpenLayers.Size(200,200); popup = new OpenLayers.Popup(id,marklonLat,size,html,true,'' , {keepInMap: true }); map.addPopup(popup); } </pre> <p>jQuery(".olPopup").remove(); -- This will close all the popup's on the map before you open a new popup</p> <p>html -- this is the content which will be there in the popup</p> </div>

Android OpenStreetMap 获得用户当前方向并且改变用户定位的图标的方向

类似于百度地图用户旋转 ,用户的图标也跟着旋转,指南针的功能

对托管的openstreetmap nominatim服务设置基于ip的限制

<div class="post-text" itemprop="text"> <p>I have installed openstreetmap nominatim planet file in my server. </p> <p>To install this I have followed their guidelines from this page <a href="http://wiki.openstreetmap.org/wiki/Nominatim/Installation" rel="nofollow noreferrer">http://wiki.openstreetmap.org/wiki/Nominatim/Installation</a> . </p> <p>I want to limited nominatim api access by blocking all ip except one ip.</p> <p>How can I do this? I have check nominatim settings.php file but it only allow to block in case of abuse. </p> </div>

在PHP中使用Nominatim进行反向地理编码

<div class="post-text" itemprop="text"> <p>I am trying to perform some reverse geocoding in php. Unfortunately, I am getting an error.</p> <pre><code>$lon = 100.753; $lat = 13.69362; function getAddress($RG_Lat,$RG_Lon) { $json = "http://nominatim.openstreetmap.org/reverse?format=json&amp;lat=".$RG_Lat."&amp;lon=".$RG_Lon."&amp;zoom=27&amp;addressdetails=1"; $jsonfile = file_get_contents($json); $RG_array = json_decode($jsonfile,true); foreach ($RG_array as $name =&gt; $value) { if($name == "display_name") { $RG_address = $value; break; } } return $RG_address; } $addr = getAddress($lat,$lon); echo "Address: ".$addr; </code></pre> <p>Here are the errors which I am getting.</p> <pre><code>&lt;b&gt;Warning&lt;/b&gt;: file_get_contents(http://nominatim.openstreetmap.org/reverse?format=json&amp;amp;lat=13.69362&amp;amp;lon=100.753&amp;amp;zoom=27&amp;amp;addressdetails=1): failed to open stream: Connection timed out in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;22&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; &lt;b&gt;Warning&lt;/b&gt;: Invalid argument supplied for foreach() in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;25&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined variable: RG_address in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;34&lt;/b&gt;&lt;br /&gt; Address: &lt;br /&gt; </code></pre> <p>If I use below code in Angular then it is working fine.</p> <pre><code>showCountry($scope.latitude,$scope.longitude); function showCountry(lat, lon) { $.getJSON('//nominatim.openstreetmap.org/reverse?json_callback=?&amp;format=json', {lat: lat, lon: lon}, function(data) { console.log(data.address.town); console.log('suburb- '+data.address.suburb); console.log('county/district -'+data.address.county); console.log('state - '+data.address.state); console.log(data.address.postcode); console.log(data.address.country); }); } </code></pre> <p>I can't perform this action on the client side; that's the reason I need to do it in php.</p> </div>

如何通过OpenStreetMap PHP Api更新节点

<div class="post-text" itemprop="text"> <p>I'm trying to update a node that i've created before via the OSM PHP API. I've developed some functions that makes some CRUD operations by using the open street map API. </p> <p>My update function is getting the node and the changeset id to make this operation, then i'm making a put request via this url <code>/api/0.6/node/#id</code></p> <pre><code> $ls_url_update_node = $this-&gt;get_api()-&gt;get_base_url() . "/api/0.6/node/".$this-&gt;get_id(); $lo_requete = Request::put($ls_url_update_node); $ls_xml_node = $this-&gt;generate_xml($po_changeset); $lo_requete = Request::put($ls_url_update_node) -&gt;sendsType('text/xml') -&gt;addHeader('Authorization', $this-&gt;get_api()-&gt;get_authorization_header()) -&gt;body($ls_xml_node); $lo_response = $lo_requete-&gt;send(); </code></pre> <p>The genarate_xml function try to generate a valid XML that respect the OSM specifications.</p> <pre><code>&lt;osm&gt; &lt;node id="123" lat="..." lon="..." version="142" changeset="12" user="fred" uid="123" visible="true" timestamp="2005-07-30T14:27:12+01:00"&gt; &lt;tag k="note" v="Just a node"/&gt; ... &lt;/node&gt; &lt;/osm&gt; </code></pre> <p>The OSM Api returns this error message : Cannot parse valid node from xml string. Mayeb i've skip some differences between the creation and the update of a node. So any help please.</p> </div>

将KML文件上传到数据库并显示在OpenLayers Map上

<div class="post-text" itemprop="text"> <p>I want to create a simple form on my wordpress site so that people can upload KML files which will then be stored in the db and the route shown on on openlayers map - openstreetmap. </p> <p>The project is for a hiking site for storing hiking routes.</p> <p>Any docs for this/ forums / advice. I'm completely new to this map stuff. </p> <p>Cheers</p> <p>Andy</p> </div>

用sumo的交通仿真,从osm下载的地图不会加入车辆,找不到路径的名称

从osm上下载下来的地图,但是加入车辆的时候找不到路径,具体的说就是不知道路径是什么,求大神帮帮我啊,怎么找路径,或者我是不是漏掉了什么

无法访问OSM数据库

<div class="post-text" itemprop="text"> <p>I am trying to get the speed limit using the OSM through php. But, I am unable to do that because I am getting the message as written below:</p> <blockquote> <p>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</p> </blockquote> <p>What could be the problem? Below is my php file. Note: the code is still incomplete, I'm for now testing if I am able to access the OSM database.. But I cant. I hope someone could point me to the right direction..</p> <pre><code> &lt;?php $lat = 24.32633; $lng = 54.58061; $latm = -0.00015 + $lat; $latp = 0.00015 + $lat; $lngm = -0.00015 + $lng; $lngp = 0.00015 + $lng; //$json_url = 'http://overpass-api.de/api/interpreter?data=[out:json];node(24.326180, 54.580460,24.336580, 54.580860);way(bn);(._;&gt;;);out;'; $json_url = 'http://overpass.osm.rambler.ru/cgi/interpreter'; $data = '&lt;query type="way"&gt; &lt;bbox-query s="' . $lngm . '" w="' . $latm . '" n="' . $lngp . '" e="' . $latp . '"/&gt; &lt;!--this is auto-completed with the current map view coordinates.--&gt; &lt;/query&gt; &lt;print/&gt;'; $ch = curl_init( $json_url ); $options = array( CURLOPT_POST =&gt; true, CURLOPT_HTTPHEADER =&gt; array('Content-type: application/json') , CURLOPT_POSTFIELDS =&gt; $data, CURLOPT_RETURNTRANSFER =&gt; true, ); curl_setopt_array( $ch, $options ); $result = curl_exec($ch); echo curl_exec($ch); /*$resultArr = explode("&lt;",$result); foreach ($resultArr as $val) { $temp = explode('"', $val); //check the size of the array, if it is == 5, then do if ($temp[1]=="maxspeed") $speedlimit=$temp[3]; } echo '{"speedlimit": "120"}'; */ ?&gt; </code></pre> </div>

OSM:两点之间的编程线进展

<div class="post-text" itemprop="text"> <p>For an exercise/project in PHP, I have to program a route (with progression), but without being precise to the streets to be borrowed (as we know on GPS) but with lines between two points. Example: <a href="https://i.stack.imgur.com/qmRNz.png" rel="nofollow noreferrer">example route</a></p> <p>The additional difficulty is to be able to display the progress on the line, starting from a percentage, the goal is therefore to have an image (like car, man or bicycle) on the straight line. I have already worked with leaflet.js, but if another library is more appropriate I am taker.</p> <p>I use this for the moment, for the points (Departure and arrival):</p> <pre><code>function placeMarkerDepartureArrival() { // Departure L.marker([varGPS[0].lat, varGPS[0].lng], {icon:myIconAD}).addTo(map); // Arrival L.marker([varGPS[1].lat, varGPS[1].lng], {icon:myIconAD}).addTo(map); } </code></pre> <p>If you have any examples or site, I am taker.</p> </div>

尝试使用ajax创建带有click函数的传单映射,将lat lng坐标发布到php文件中

<div class="post-text" itemprop="text"> <p>I'm trying to create Leaflet map that when the map is clicked on, it creates a marker and posts the coordinates in the console. Then the coordinates are posted via ajax to a php file and then inserted into a mysql database. </p> <pre><code> var map; var centerlatlng = L.latLng(34.248987,-118.531891); var lat; var lng; var markerLatLng; $(document).ready(function (){ $('.aPopOver').popover({ 'container': 'body' });// this works var aLayerOne = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', { key: 'f4cedc5a042746e8813e1db9697e92e5', styleId: 22677, attribution: 'Map data &amp;copy; &lt;a href="http://openstreetmap.org"&gt;OpenStreetMap&lt;/a&gt;, Created @ &lt;a href="http://www.csun.edu/csbs/departments/geography/"&gt;CSUN Geography&lt;/a&gt;', maxZoom: 18, minZoom: 4 }); var aLayerTwo = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', { key: 'f4cedc5a042746e8813e1db9697e92e5', styleId: 82102, attribution: 'Map data &amp;copy; &lt;a href="http://openstreetmap.org"&gt;OpenStreetMap&lt;/a&gt;, Created @ &lt;a href="http://www.csun.edu/csbs/departments/geography/"&gt;CSUN Geography&lt;/a&gt;', maxZoom: 18, minZoom: 4 }); map = L.map('myMap', { center: centerlatlng, zoom: 12, layers: [aLayerOne] }); // Define an EVENT for the map </code></pre> <p>map.on('click', function(e) {</p> <pre><code> console.log("You clicked on the map !"); console.info("lat = " + e.latlng.lat + " " + "long= " + e.latlng.lng); var lat = $(e.latlng.lat); var lng = $(e.latlng,lng); var markerLatLng = L.marker([e.latlng.lat,e.latlng.lng]).addTo(map); $.ajax({ type:"post", url: "post.php", data:{lat: lat}, success:function() { alert("Post Successful!"); } }); }); // end of map on click event // Add a Layers Control var baseMaps = { "Default": aLayerOne, "Night Rider": aLayerTwo }; L.control.layers(baseMaps).addTo(map); // Add a Scale Control L.control.scale().addTo(map); // Add a Full Screen Control // use "new" in its construct new L.Control.FullScreen().addTo(map); // Add a Locate Control // images folder must be within the same folder as L.Control.Locate.css file </code></pre> <p>}); // end document ready </p> </div>

XML插入变量PHP

<div class="post-text" itemprop="text"> <p>i have variable <code>$result</code> contains the xml string as below:</p> <pre><code>&lt;reversegeocode timestamp="Mon, 12 Sep 16 07:52:44 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="format=xml&amp;lat=30&amp;lon=-95&amp;addressdetails=1"&gt; &lt;result place_id="60369529" osm_type="way" osm_id="21077989" ref="County Road 6042" lat="30.0103064" lon="-95.0042308" boundingbox="30.0030833,30.0158095,-95.005969,-95.0038698"&gt; County Road 6042, Sheeks, Liberty County, Texas, 77336, United States of America &lt;/result&gt; &lt;addressparts&gt; &lt;road&gt;County Road 6042&lt;/road&gt; &lt;hamlet&gt;Sheeks&lt;/hamlet&gt; &lt;county&gt;Liberty County&lt;/county&gt; &lt;state&gt;Texas&lt;/state&gt; &lt;postcode&gt;77336&lt;/postcode&gt; &lt;country&gt;United States of America&lt;/country&gt; &lt;country_code&gt;us&lt;/country_code&gt; &lt;/addressparts&gt; &lt;/reversegeocode&gt; </code></pre> <p>I am new in PHP need to insert into variables city (if city not exist city= county), state and zip code tags only which is under <code>&lt;addressparts&gt;</code> tag. All rest data can be ignored. I don't know how to do it </p> </div>

如何在我的mysql数据库中获取planet-latest.osm.bz2?

<div class="post-text" itemprop="text"> <p>I have an Intel i3-2350M CPU @ 2.30GHz with Windows 7, 64 bit, 4GByte Ram and enough free HD space.</p> <p>The openstreetmap-file planet-latest.osm.bz2 is very big and compressed. (The version I have is 36 GByte compressed, and I believe it's like 100 GByte uncompressed. I have a mysql-database running, that I installed with XAMPP. (So I have apache and php available, too.)</p> <p>My questions are: </p> <ol> <li>The OSM-project seems to have switched to postgresql and postgis. Is this really better (===faster) than MySql? (I strongly doubt that.)</li> <li>Is there a set of commands to get the compressed file into the database? Or would it reduce the risk of failure of the commands if I first decompress it? 2b. Could I discard of all XML-nodes that are not neccessary for the graphical output in the process of importing the data into the database? (With one stroke. :P )</li> <li>It's possible for me to convert the data to a .csv-file (out of the XML): Would that make it more complacent to get the data into the database?</li> <li>How long will the machine take? I can't let it run for hours without supervision. (I can break up the big file in smaller files, though I deem this to be error prone and not advisable.)</li> </ol> <p>Greetings John</p> <p>P.S. I have most if not all standard programs at hand that are linked ont he OSM-wiki. (Though the OSM-wiki is outright deficient and a bit outdated about the currently available tools.)</p> </div>

JQuery:如何使用json中的Coordinates添加Leaflet标记

<div class="post-text" itemprop="text"> <p>I have a problem creating a marker on my leaflet map with coordinates from a json array.</p> <p>json example:</p> <blockquote> <p>{"id":"1","longitude":"8.1876","latitude":"50.1297","name":"Rhineland-Palatinate"}</p> </blockquote> <p>(background info: this comes from a PHP file that fetches data from a database which updates the current position every 10 seconds)</p> <p>The jquery code: It creates the map on my html and upon the "get_marker" click event it starts ajax which pulls a new json every 10 seconds from my .php file</p> <pre><code>$(document).ready(function () { var map = L.map('map', { center: [50.0231, 8.8849], zoom: 9 }); L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '&amp;copy; OpenStreetMap contributors' }).addTo(map); $("#get_marker").click(function(event){ startajax(); alert("get marker clicked"); }); $("#delete_marker").click(function(event){ deletemarkers(); alert("marker deleted"); }); function startajax () { $.ajax({ url: ('query_fetcharray.php'), data: {}, type: 'POST', timeout: 10000, dataType: 'json', error: function() { alert('Error, no Data received!'); }, success: drawmarker }) }; </code></pre> <p>everything above seems to be working fine The Problem is getting the actual marker on the map with the json coordinates. Nothing shows up on my map.</p> <p>I tried accessing the long and lat values with json.longitude/json.latitude and then converting these into float =&gt; then saved in JS variables: var longitude. I then put the varibles into the L.marker.</p> <p>my code:</p> <pre><code>function drawmarker (json) { var longitude = parseFloat(json.longitude); var latitude = parseFloat(json.latitude); L.marker([longitude, latitude], { clickable: true }) .bindPopup('hello') .addTo(map); }; </code></pre> <p>The Problem seems to be the actual variables since hardcoding a set of coordinates into L.marker works fine.</p> </div>

如何获取城市路网数据

![图片说明](https://img-ask.csdn.net/upload/201711/28/1511835252_480850.png) 语言不限 怎么获取城市路网数据,然后绘制成路网地图

如何使用PHP和Javascript将MySQL中的数据显示到标记上的传单弹出窗口中?

<div class="post-text" itemprop="text"> <p>Ok, this is my first time asking a question here. Please don't bully me. </p> <p>This has been asked before and I tried to solve it myself, yet it just won't work.</p> <p>Here is my problem: As stated in the question, I can't seem to call the data from MySQL into the marker's popup.</p> <p>I tried to use <code>&lt;code&gt;json_encode&lt;/code&gt;</code> to print it in the Javascript popup.The result is either <code>show [object] [object]</code> in the popup, or the leaflet map won't load at all. If I remove the <code>&lt;code&gt;marker.bindPopup()&lt;/code&gt;</code>, the code works fine.</p> <p>Here is the code :</p> <pre><code>&lt;div id="map" style="width: 800px; height: 500px;"&gt;&lt;/div&gt; &lt;?php $result = mysqli_query($konek,"SELECT dep,mag FROM data_gempa_jawa"); $rows = array(); while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } ?&gt; &lt;!-- This is for the leaflet maps --&gt; &lt;script type="text/javascript"&gt; &lt;?php include "planelatlong.php"; ?&gt; var tiles = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '&amp;copy; &lt;a href="//openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors, Points &amp;copy 2012 LINZ' }); var map = L.map('map', { center: L.latLng(-6.6, 106.42), zoom: 5, layers: [tiles] }); var mcg = L.markerClusterGroup({ chunkedLoading: true, //singleMarkerMode: true, spiderfyOnMaxZoom: true }); for (var i = 0; i &lt; planelatlong.length; i++) { marker = new L.marker([planelatlong[i][1],planelatlong[i][2]]); marker.bindPopup("&lt;?php print json_encode($rows); ?&gt;"); mcg.addLayer(marker); marker.on('click', onClick); } function onClick(e) { var popup = e.target.getPopup(); var content = popup.getContent(); } map.addLayer(mcg); &lt;/script&gt; </code></pre> <p>Here is the "planelatlon.php" code :</p> <pre><code>&lt;?php include "koneksi.php"; $select = mysqli_query($konek,"SELECT id,lat,lon FROM data_gempa_jawa"); if ( ! $select ) { echo mysqli_error(); die; } $data = array(); echo "var planelatlong = ["; for ($x = 0; $x &lt; mysqli_num_rows($select); $x++) { $data[] = mysqli_fetch_assoc($select); echo "[",$data[$x]['id'],",",$data[$x]['lat'],",",$data[$x]['lon'],"]"; if ($x &lt;= (mysqli_num_rows($select)-2) ) { echo ","; } } echo "];"; mysqli_close($konek); ?&gt; </code></pre> <p>Thanks a lot!</p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大胆预测下未来5年的Web开发

在2019年的ReactiveConf 上,《Elm in Action》的作者Richard Feldman对未来5年Web开发的发展做了预测,很有意思,分享给大家。如果你有机会从头...

立即提问
相关内容推荐