I already wrote a android apps to upload the lat and long to MySQL database(updated every 2min).
now, i have no idea how to show the real time location on Google map in the website(php,javascript,html)
which means how to dynamic update the Google map markers every 2 min [get the last two minutes records from MySQL database
and show the markers(update or disappear)]
and after i click the marker, it should show the info[get from mysql database(not important point because it same with static Google map!?]
just like this: http://traintimes.org.uk/map/tube/
I just know how to do when i just get 1 time (Static Google map!?) with my limited knowledge.
I have already searched same question in stack overflow and google
but i am sorry i still no idea how to do it because of my lack of knowledge.
Real time Google Map
anyone could give me some tutorial website or suggestion?
At last, thank all of you
and
I still a learner of English,I am sorry about any wrong grammar.
Real-time Tracking Geo Latitude/Longitude on a Map
You are looking to update coordinate entities (lat/lon position) on a map (google maps or otherwise) in real-time as the updates occur. Here is a blog post that may get you started in the right direction: http://blog.pubnub.com/streaming-geo-coordinates-from-mongodb-to-your-iphone-app-with-pubnub-using-websocket-sdk/ - this uses MongoDB and Ruby rather than PHP and MySQL. However it will be easy to get things setup in this case with a real-time map in PHP and MySQL on an HTML page with the following details. And there is a video too: https://vimeo.com/60716860
Using MySQL to Trigger Update in Real-time
First you'll want to use either MySQL triggers to push the Lat/Long coords - Invoke pusher when mysql has changed - this uses MySQL Triggers
Or as an alternative you may want to use PHP directly to invoke the push signal using a PHP push SDK as follows: https://github.com/pubnub/php#php-push-api
$pubnub->publish(array(
'channel' => 'live_map_coords',
'message' => array( 12.3482, 8.3344 )
));
Receiving The Push Message in JavaScript and Showing the Updates on a Map
<script src=//pubnub.a.ssl.fastly.net/pubnub-3.4.5.min.js></script>
<script>(function(){
PUBNUB.init({
subscribe_key : 'demo'
}).subscribe({
channel : 'live_map_coords',
callback : function(lat_lon) { alert(lat_lon) }
});
})();</script>
Once you have an map.html page with the above code in it, you can change the alert(lat_log) message popup with drawing coords on a map. Here is a fully working map drawn example using D3 JavaScript SVG rendering Framework: https://github.com/stephenlb/pubnub-mongo-pipe/blob/master/phone/map.html
NOTE: This is only a starting point and provides you with references on getting started to make it easy and simple, yet flexible based on the direction you will be taking your app.
Next Steps to Piece Together the Real-time Geo Map
You will next want to do the following to complete the process and join together all the separate components listed here.
Modify the map.html page for your purposes to display always-visible dots. Note that in the video the dots are temporary beacons that display and vanish rapidly. You'll want to make them persist on the map. This is basically the "Make it look the way you want it" step.
Decide how and when you want to trigger the TCP Socket Push events from PHP or MySQL directly. I'd recommend the PHP approach.
Related
I have read about Google's Geocoding Service which allows named locations (such as Manchester) to be mapped to coordinates from Google's DB so that markers can be placed on the Google Map: https://developers.google.com/maps/documentation/javascript/geocoding#Geocoding
In my circumstance I have a MySQL DB with a table jobs defined. In this table I store (unsurprisingly) job information, e.g. salary, job title, reference, etc. In this table is a column for the job location too. Most of the time it contains the city (or city plus postcode). The odd few times it is either NULL or has a string such as "No location specified".
To view these records I have a webserver running on my test machine and I display the records of the table in my browser with some HTML and general php script (a DB driven intranet page).
I have now split this page up into two sections. Using the Google Maps v3 API I have the bottom half containing the Google Map. What I am trying to achieve is:
automatic placing of markers based on the location strings in the
location column.
click-able markers where on-click they produce the
info window (which will contain job Title, etc).
What I want to know is what is the best way to do this?
I have read some similar posts here on SO where users have had a similar situation. From these readings I can ascertain that some OP's have made the effort to store the long/lat of the location of their record at the time it was inserted into the table and THEN read the long/lat with Javascript to produce the markers.
To do this I would need to modify some code and the table. This is one option, but I'd rather explore the other which is perhaps using Google's Geocoding service? Has anybody any experience with this? Any advice, recommendation you can give?
Also, lets say I used the latter option. I use PHP script to load the records from the DB. How would I pass the locations to Javascript so that the Google Map API can interrogate for long/lat with the Geocoding service? Is this a less optimal way of achieving it?
Thanks.
Just use Gmap3 Library, and you provide it an address...like so....
http://gmap3.net/en/catalog/18-data-types/address-63
You setup a div...
<div id="test" width=500 height=500></div>
Then your Jquery inserts the map into the div....
$("#test").gmap3({
marker:{
address: "Haltern am See, Weseler Str. 151"
},
map:{
options:{
zoom: 14
}
}
});
The address can be echoed from your PHP (this is considered bad practice though)
$("#test").gmap3({
marker:{
address: '<?php echo $addressfromDB;?>'
},
map:{
options:{
zoom: 14
}
}
});
But its better to do an ajax call, and then include this code in the success callback
$.getJSON('getlocation.php', function(data){
$("#test").gmap3({
marker:{
address: data.address // or whatever structure your json is in.
},
map:{
options:{
zoom: 14
}
}
});
});
That should get you started :)
It sounds like you have everything in place except for the Javascript and the way to get your data from the PHP script.
So lets start with getting the data from the PHP script in to the Javascript. The way to do this is using AJAX (for learning it, not an official source: http://www.w3schools.com/ajax/ajax_intro.asp). Once the web page has been loaded, Javascript can load more information by using an XMLHttpRequest object (or jQuery.ajax() if you prefer to use a Javascript framework). Basically this is Javascript loading a new page in the background and then doing stuff with the contents on it's own. You'll need to set up the PHP script (or make another one - I'm not familiar with this part) to provide the information that you want at a separate URI than the page you're visiting. Then you use this URI in the Javascript XMLHttpRequest. Typically you would get the PHP script to provide data in a form that's easy for computers to understand such as JSON (recomended) or XML (as apposed to HTML which is easy for human's to understand - once rendered). This procedure is called an API. In your JavaScript, you'll use JSON.parse() to turn the response text into actual variables that you can do stuff with.
Once you've got the addresses in Javascript, use the geocoding API you mentioned to turn them into GPS coordinates, and then the Google Maps Javascript API to place markers on the map: https://developers.google.com/maps/documentation/javascript/overlays#Markers. You can add an info window as well (search for InfoWindo in the above page - apparently I can only include 2 links).
As you've mentioned, it's probably a better idea to geocode all of the addresses and keep the lat/lon stored in the database. The biggest reason for this that if you geocode in Javascript as described above, then every time the user loads the page, geocoding will be re-done. This has two issues: 1. For Google, this is an expensive operation that costs them resources. 2. For you, this means it takes longer for the map to populate (because you have to wait on Google's response to your AJAX call - the geocoding one, not the one you'll be implementing as described above) and you might run into Google's usage limits which are in place because of 1. If you decide to geocode ahead of time and store the results in your database, you should be using "The Google Geocoding API", not the Javascript Geocoding Service. I can't add another link to it, but just Google "The Google Geocoding API".
I hope that helps, and if someone else wants to update my answer with more links, feel free.
I'm working on a project of mine, which would require users to add markers on a google maps api map, that would be later on passed to a DB, which would store all overlay coordinates and once the map is loaded (in case the user has the required permissions, of course), a for loop will add all markers from the DB into the page and will visualize them (circles with static radius, but various coordinates). So long story short, I need a way to enable the users to put those markers themselves there and a way to read the LatLng coordinates and pass them to a script, which will flush them in the DB. One way (in case it's possible, of course) is to use the context menu and add an option like "set marker here", that would pass the coords to a function flushing them to the DB. Of course the workaround is RMB-> what is here, copy the coords and enter 'em in a input field, which almost inevitably will doom the project to an epic fail, because nobody will do that, but instead will just enter some random numbers, which would be moronic, because the project basically depends on those coordinates.
So is there a way to somehow automate the adding process of an overlay element in the api, that I could use? I googled around for a few days, tried to find something in the v3 help too, but didn't find anything really helpful so far..
Thanks in advance! All comments and help would be appreciated!
Cheers,
vlex
What I'm trying to create, is an app that will allow me to download list of places near given coordinates. With Wikipedia api it's fairly simple:
http://api.geonames.org/findNearbyWikipedia?lat=47&lng=9&username=some-username
This code run with curl in php gives me an xml response with list of places and possibly their descriptions along with exact coordinates matching the given ones (which are not exact). Is there a way I can do it as simple as above, with GoogleApi? This link: http://code.google.com/intl/pl/apis/maps/documentation/mapsdata/developers_guide_protocol.html#SpatialSearch tells very briefly about spatial search, and I can't find any info on this topic in the internet - like where can I find my user and mapid, how can I get my authorization token.
I know, that this may seem a stupid question for you, but google maps api doc is vast, and I just can't find anything more, than in this link above.
In sum:
I don't want to embed google map on my page, I just want to get places near given coordinates, and list them to my users, and I have to do this on server-side.
At the very top of that page, it says "Google Maps Data API (No Longer Available)", so I don't think you should use that.
Instead, look at Google Places API. It's only a developer preview, but looks like what you need.
Interesting problem: I want our sales staff of 3 to use the same master PDF (strictly on our own server from within our intranet) to create a unique document set for each client of our business, which document set includes a contract.
A state regulator randomly audits our supply of contract forms, and assesses a fee for each missing contract, so the contracts must be sequentially numbered with no apparent gaps. I want the "Finalize Contract" button in my PDF to run an Acrobat JavaScript that posts a request to a webservice written in PHP, which webservice should connect to a MySQL table, autoincrements the number in in question in the table, and return the value to the Acrobat JavaScript for assignment to the proper field.
I have done enough research to know what I want to do. I am enough of a coding virgin to not know the nuts and bolts of how to do it. I can take PMs on this for an open dialogue off the board if you wish, just need to get it done.
You might want to have a look at JQuery and it's Ajax function for the part of retrieving PHP data from JavaScript: http://api.jquery.com/jQuery.get/
Regarding the PHP part, you want to connect to a database and fetch and update some information. This might help: http://de.php.net/manual/de/function.mysql-query.php
I have a MySQL Database of more or less 100 teachers, their names, and their phone numbers, stored in tables based upon their department at the school. I'm creating an iPhone app, and I've found that UITableViews and all the work that comes with it is just too time consuming and too confusing. Instead, I've been trying to create a web page on my server that loads all the data from MySQL and displays it using HTML, PHP, jQuery, and jQTouch for formatting.
My concept is that the separators will be by department, and the staff will be sorted alphabetically under each department. On the main page, each person's name will be clickable so they can go to ANOTHER page listing their name, email address, and telephone number, all linked so that the user can tap on the email or number and immediately email or call that person, respectively.
HOWEVER, I am completely at a loss for how I should start. Can anyone point me in the right direction for displaying the data? Am I going about it wrong in using PHP? Should I opt for something COMPLETELY different?
PHP to manage the database interaction and generate HTML is fine. There are heaps of tutorials on how to do that (e.g. http://www.w3schools.com/PHP/php_mysql_intro.asp) How to make it look nice is beyond the scope of this answer, and I'd recommend you search for table/CSS examples to get some ideas of what looks good and how they're implemented. If you need interactivity such as expanding rows or changing colors, then jQuery would be an appropriate next step, though you certainly don't need more than HTML + CSS for a nice looking table representation.
What I don't know about is the auto email/call functionality you're after, and whether you can get that "for free" from whatever is rendering the HTML. That's iPhone specific, not PHP/jQuery/etc... And I'd second Alex's advice that if UITableView is the right tool for the job then you will definitely be better off in the long run just buckling down and learning it. (And going through that will probably make pickup up other parts of the API much easier to boot.)
Instead of loading my PHP in my <body>, I created a function that retrieved the data via mysql_fetch_assoc(), which added all the information and created each individual div of data AS WELL AS injecting a <script> to $.append() the list item content for each item retrieved via the mysql_fetch_assoc(). Thanks for the responses anyway!