geocoder api radar search and multiple markers issue - php

my script as below. I have to search the pincode and based on search i have to show locations on map
Ques 1: if i have 2 results for same pincode, then also one marker is coming on the map. i want to show seperate markers.
Ques 2: i want to radar search as well using pincode. like if pincode 07201 and 07202 are very near areas then i should get results for both. i tried using radius in my response, but its not working
<script>
var map;
<!-- var marker; -->
function initialize()
{
var mapOptions = {
center: new google.maps.LatLng('40.71338', '-74.193246'),
zoom: 8,
scrollwheel: false,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(40.71338, -74.193246),
map: map,
});
}
jQuery('#searchPincodeForm').submit(function (event) {
event.preventDefault();
var geocoder = new google.maps.Geocoder();
var search_val=$('#country').val();
jQuery.ajax({
type: 'post',
data:{
'pincode':search_val,
},
url: 'searchPincode.php',
success:function(response){
if(response != ''){
$("#result").html(response).show();
geocoder.geocode({
'address': search_val }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var position = results[0].geometry.location;
map.setCenter(position);
marker.setPosition(position);
}
})
} else{
$("#result").html("Sorry Dealer not available at this location. For more information please mail at info#movemaxoil.com").show();
}
}
});
});
</script>
Response i get from geocode:
{
"results": [{
"address_components": [{
"long_name": "07108",
"short_name": "07108",
"types": ["postal_code"]
},
{
"long_name": "Newark",
"short_name": "Newark",
"types": ["locality", "political"]
},
{
"long_name": "Essex County",
"short_name": "Essex County",
"types": ["administrative_area_level_2", "political"]
},
{
"long_name": "New Jersey",
"short_name": "NJ",
"types": ["administrative_area_level_1", "political"]
},
{
"long_name": "United States",
"short_name": "US",
"types": ["country", "political"]
}
],
"formatted_address": "Newark, NJ 07108, USA",
"geometry": {
"bounds": {
"northeast": {
"lat": 40.73179289999999,
"lng": -74.1830549
},
"southwest": {
"lat": 40.713114,
"lng": -74.21835
}
},
"location": {
"lat": 40.7235275,
"lng": -74.197388
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 40.73179289999999,
"lng": -74.1830549
},
"southwest": {
"lat": 40.713114,
"lng": -74.21835
}
}
},
"place_id": "ChIJK0xWNjlTwokRLb_3zFLt8zM",
"types": ["postal_code"]
}],
"status": "OK"
}

So the issue is here:
var position = results[0].geometry.location;
map.setCenter(position);
marker.setPosition(position);
Your ajax response may contain more than one location point in it, but in the above code you are using only the first location point results[0].geometry.location here. So instead of results[0] you have to loop through all the results array so that multiple points are mapped on your mark.

Related

How to send map coordinates to javascript file - with Laravel?

I have a contact page. This page contains map information. This map is generated by the script file. How do I change the coordinates dynamically?
Js file content;
var MY_MAPTYPE_ID = 'style_KINESB';
function initialize() {
var featureOpts = [
{
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#666666"
}
]
},
{
"featureType": 'all',
"elementType": 'labels',
"stylers": [
{ visibility: 'simplified' }
]
},
{
"featureType": "landscape",
"elementType": "all",
"stylers": [
{
"color": "#e2e2e2"
}
]
},
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road",
"elementType": "all",
"stylers": [
{
"saturation": -100
},
{
"lightness": 45
},
{
"visibility": "off"
}
]
},
{
"featureType": "road.highway",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.arterial",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"color": "#aadaff"
},
{
"visibility": "on"
}
]
}
];
var myGent = new google.maps.LatLng(40.6946703,-73.9280182);
var Kine = new google.maps.LatLng(40.6946703,-73.9280182);
var mapOptions = {
zoom: 11,
mapTypeControl: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_TOP,
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID,
scaleControl: false,
streetViewControl: false,
center: myGent
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var styledMapOptions = {
name: 'style_KINESB'
};
var image = 'images/resource/mapmarker.png';
var marker = new google.maps.Marker({
position: Kine,
map: map,
animation: google.maps.Animation.DROP,
title: 'B4318, Gumfreston SA70 8RA, United Kingdom',
icon: image
});
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
}
google.maps.event.addDomListener(window, 'load', initialize);
The area I want to access through the Laravel blade. I want to make the coordinates dynamic.
var myGent = new google.maps.LatLng(40.6946703,-73.9280182);
var Kine = new google.maps.LatLng(40.6946703,-73.9280182);
contact.blade.php
#extends('layouts.frontend.master')
#section('title', 'Empathy - Become Volunteer')
#section('content')
#endsection
Please help me. Thank you very much for your help.
My solution here. I also worked. I'm waiting if you have better solutions.
Firstly. I am add #yield("javascript") directive in master.blade.php file. I add on to the js file.
#yield('javascript')
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAAz77U5XQuEME6TpftaMdX0bBelQxXRlM&callback=initMap" type="text/javascript"></script>
<script src="{{ asset('empathy/frontend/assets/js/googlemaps1.js') }}"></script>
<!-- Custom script for all page -->
<script src="{{ asset('empathy/frontend/assets/js/script.js') }}"></script>
Later edit contact.blade.php
#extends('layouts.frontend.master')
#section('title', 'Empathy - Become Volunteer')
#section('content')
#endsection
#section('javascript')
<script>
var x = JSON.parse('{!! json_encode($coordinate_array[0]) !!}');
var y = JSON.parse('{!! json_encode($coordinate_array[1]) !!}');
</script>
#endsection
ContactPageController.php
$contact = Contact::first();
$coordinate_array = explode(',', $contact->coordinates); // 40.6946703,-73.9280182
This way my solution worked.

parse Json response with attributes

I'm trying to parse Json result below fromAjax response. Foreach CostingItem i need to access to UnitPrice.Amount, but I got error.
Can someone help me to access items?
I got this response from Laravel based webservice.
{
"CostingItem": [{
"#attributes": {
"Description": "Basic Price",
"Quantity": "1",
"PassengerRPH": "1",
"PriceBasis": "Passenger"
},
"UnitPrice": {
"#attributes": {
"Amount": "1823.82",
"OriginalAmount": "1974.32"
}
},
"ExtendedPrice": {
"#attributes": {
"Amount": "1823.82",
"OriginalAmount": "1974.32"
}
},
"Commission": {
"#attributes": {
"Rate": "11.00",
"Type": "P"
}
}
}, {
"#attributes": {
"Description": "Basic Price",
"Quantity": "1",
"PassengerRPH": "2",
"PriceBasis": "Passenger"
},
"UnitPrice": {
"#attributes": {
"Amount": "1823.82",
"OriginalAmount": "1974.32"
}
},
"ExtendedPrice": {
"#attributes": {
"Amount": "1823.82",
"OriginalAmount": "1974.32"
}
},
"Commission": {
"#attributes": {
"Rate": "11.00",
"Type": "P"
}
}
}]
}
here is the script used in Ajax:
$.ajax({
type: "POST",
url: "/public/fetch-bambini",
data: {
id: d,
tipologia: tipologia,
bambini: bambini,
neonati: neonati,
adulti: adulti
},
success: function(response) {
$.each(response.CostingItem, function(k, v) {
console.log(v);
});
}
});
This return this response:

Converting .JSON list to google maps

Hi I have a aircraft json list on a pi connected to a home network that I would like to convert to a google maps format similar to flightradar24.com etc. I have tried multiple ways but have not got very far. Any help would be good I am only a beginner with coding so excuse the not so good explanation. Thanks :)
{ "now" : 1497814126.3,
"messages" : 20531195,
"aircraft" : [
{"hex":"c82089","squawk":"5625","flight":"ANZ519 ","altitude":3250,"vert_rate":3008,"track":79,"speed":225,"messages":88,"seen":69.0,"rssi":-24.9},
{"hex":"c81881","squawk":"0262","flight":"ANZ101 ","lat":-36.881150,"lon":174.829440,"nucp":7,"seen_pos":0.3,"altitude":9725,"vert_rate":3136,"track":269,"speed":330,"messages":1360,"seen":0.1,"rssi":-8.1},
{"hex":"aae597","squawk":"0767","flight":"AAL83 ","lat":-36.149918,"lon":175.464592,"nucp":7,"seen_pos":0.4,"altitude":23400,"vert_rate":-1792,"track":212,"speed":386,"messages":1734,"seen":0.1,"rssi":-24.8},
{"hex":"c81dd5","squawk":"0256","flight":"QFA140 ","lat":-36.892043,"lon":174.183456,"nucp":7,"seen_pos":0.0,"altitude":21800,"vert_rate":2240,"track":270,"speed":398,"messages":4023,"seen":0.0,"rssi":-27.1},
{"hex":"c8178c","squawk":"0260","flight":"ANZ937 ","lat":-36.605002,"lon":173.758772,"nucp":6,"seen_pos":52.9,"altitude":26675,"vert_rate":1152,"track":295,"speed":412,"messages":4913,"seen":1.4,"rssi":-32.3}
]
}
Here is a demo that shows how to view latitude/longitude data as markers on a map
var data = [{
"hex": "c82089",
"squawk": "5625",
"flight": "ANZ519 ",
"altitude": 3250,
"vert_rate": 3008,
"track": 79,
"speed": 225,
"messages": 88,
"seen": 69.0,
"rssi": -24.9
},
{
"hex": "c81881",
"squawk": "0262",
"flight": "ANZ101 ",
"lat": -36.881150,
"lon": 174.829440,
"nucp": 7,
"seen_pos": 0.3,
"altitude": 9725,
"vert_rate": 3136,
"track": 269,
"speed": 330,
"messages": 1360,
"seen": 0.1,
"rssi": -8.1
},
{
"hex": "aae597",
"squawk": "0767",
"flight": "AAL83 ",
"lat": -36.149918,
"lon": 175.464592,
"nucp": 7,
"seen_pos": 0.4,
"altitude": 23400,
"vert_rate": -1792,
"track": 212,
"speed": 386,
"messages": 1734,
"seen": 0.1,
"rssi": -24.8
},
{
"hex": "c81dd5",
"squawk": "0256",
"flight": "QFA140 ",
"lat": -36.892043,
"lon": 174.183456,
"nucp": 7,
"seen_pos": 0.0,
"altitude": 21800,
"vert_rate": 2240,
"track": 270,
"speed": 398,
"messages": 4023,
"seen": 0.0,
"rssi": -27.1
},
{
"hex": "c8178c",
"squawk": "0260",
"flight": "ANZ937 ",
"lat": -36.605002,
"lon": 173.758772,
"nucp": 6,
"seen_pos": 52.9,
"altitude": 26675,
"vert_rate": 1152,
"track": 295,
"speed": 412,
"messages": 4913,
"seen": 1.4,
"rssi": -32.3
}
];
function initMap() {
var myLatLng = {
lat: -36.363,
lng: 175.044
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: myLatLng
});
for (var i = 0; i < data.length; i++) {
var flight = data[i],
latLng = new google.maps.LatLng(flight.lat, flight.lon);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: data.flight
});
}
}
#map {
height: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAIPPUQ0PSWMjTsgvIWRRcJv3LGfRzGmnA&callback=initMap">
</script>
<div id="map"></div>

Datatable Show/Hide Checkbox is not working proferly

I am using DataTable to display the data. All the column names with check box is displaying when i click show and hide button. When i uncheck all the column and when i try to check the column name at that time the first column is getting copied or getting displayed in the all the row values.
Following is my code which i written.
$('#datatable_col_reorder').dataTable({
"processing": true,
"sAjaxSource": "<?php echo $config['ajaxUrlPath'];>json.php",
"bFilter" : true,
"fnServerData": function ( sAjaxSource , aoData, fnCallback ) {
aoData.push( { "name": "eventName", "value": $('#eventName').val() });
aoData.push( { "name": "et", "value": $('#Type').val() });
aoData.push( { "name": "vn", "value": $('#address').val() });
aoData.push( { "name": "da", "value": $('#date_added').val() });
aoData.push( { "name": "ti", "value": $('#time_added').val() });
aoData.push( { "name": "st", "value": $('#status').val() });
aoData.push( { "name": "br", "value": $('#status1').val() });
aoData.push( { "name": "cr", "value": $('#status2').val() });
aoData.push( { "name": "pr", "value": $('#spercentage').val() });
// etc
$( "#status2,#address,#spercentage" ).keyup(function() {
var table = $('#datatable_col_reorder').DataTable();
table.ajax.reload();
});
$( "#status,#Type,#date_added,#time_added,#status1,#status2" ).change(function() {
var table = $('#datatable_col_reorder').DataTable();
table.ajax.reload();
});
$.getJSON( sAjaxSource, aoData, function (json) { console.log(json); fnCallback(json) } );
},
"sDom":"<'col-sm-1 col-xs-1 col-md-1 col-lg-1 showHidebutton'C><'dt-toolbar'r>"+
"t"+
"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
"autoWidth" : true,
"rowCallback": function( nRow, aData, iDisplayIndex ) {
// responsiveHelper_datatable_tabletools.createExpandIcon(nRow);
$('td:eq(0)', nRow).html(''+aData[0]+'');
return nRow;
},
"preDrawCallback" : function() {
// Initialize the responsive datatables helper once.
if (!responsiveHelper_datatable_col_reorder) {
responsiveHelper_datatable_col_reorder = new ResponsiveDatatablesHelper($('#datatable_col_reorder'), breakpointDefinition);
}
},
"drawCallback" : function(oSettings) {
responsiveHelper_datatable_col_reorder.respond();
}
});
When i uncheck all and when i try to recheck each checkboxes, at that time the first column values are getting displayed in all other column like type,status,address etc.
Example: Consider Name: XYZ, After deselecting checkboxes if i try to recheck at that time the each column values is showing "XYZ" in status,address columns.
Thanks in advance.

EXTJS JsonStore do not load

I know this will be a repetition. But I have tried my best to solve it, all in vain. I am unable to populate even a simple grid panel!!! Obviously I am a newbie in extjs.
My js code is as follows:
Ext.onReady(function(){
var store = new Ext.data.JsonStore({
url: 'compare.php',
fields: ['name', 'area']
});
store.load();
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: 'Name', width: 100, sortable: true, dataIndex: 'name'},
{header: 'Position', width: 100, sortable: true, dataIndex: 'area'}
],
stripeRows: true,
height:250,
width:500,
title:'DB Grid'
});
grid.render('db-grid');
});
and my php is as follows:
<html>
<head>
</head>
<body bgcolor="white">
<?php
$link = pg_Connect('host=my_host port=5432 dbname=da_name user=postgres password=my_password');
$sql = "SELECT name, area FROM \"TABLE\" LIMIT 10";
if (!$link) {
echo "error";
} else {
$result = pg_query($link, $sql);
$rows = array();
$totaldata = pg_num_rows($result);
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
//echo json_encode($rows);
//echo json_encode(array('country' => $rows));
echo '({"total":"'.$totaldata.'","country":'.json_encode($rows).'})';
}
?>
</body>
</html>
And my json is as follows:
[
{
"total": "10",
"country": [
{
"name": "CULTIV",
"area": "1.10584619505971e-006"
},
{
"name": "CULTIV",
"area": "2.87818068045453e-006"
},
{
"name": "CULTIV",
"area": "6.96120082466223e-007"
},
{
"name": "CULTIV",
"area": "1.17171452984621e-007"
},
{
"name": "CULTIV",
"area": "1.25584028864978e-006"
},
{
"name": "CULTIV",
"area": "5.86309965910914e-007"
},
{
"name": "CULTIV",
"area": "4.12220742873615e-007"
},
{
"name": "CULTIV",
"area": "7.59690840368421e-006"
},
{
"name": "CULTIV",
"area": "2.47360731009394e-007"
},
{
"name": "CULTIV",
"area": "4.04940848284241e-005"
}
]
Do I need to set any proxy for this? Actually my application is running on different server than my database.
I have no experience in PostgreSQL but I advice you to use pg_fetch_object() function instead of pg_fetch_assoc() in that case.
Try something like this:
while($obj = $result->pg_fetch_object()) {
$rows = $obj;
}
echo '({"total":"'.$totaldata.'","country":'.json_encode($rows).'})';
Your JSON is malformed. Ext.data.JsonReader (automatically configured when you use a JsonStore) expects a JSON object with a root node, defined in your reader config. The reader should throw an exception if the root is undefined.
So define a root for your JsonReader:
var store = new Ext.data.JsonStore({
url: 'compare.php',
root: 'country', // required!
fields: ['name', 'area']
});
And your JSON should look like this:
{
"total": 10,
"country": [{
"name": "CULTIV",
"area": "6.96120082466223e-007"
},{
...
}]
}

Categories